Including jars in classpath on commandline (javac or apt)
Try the following:
java -cp jar1:jar2:jar3:dir1:. HelloWorld
The default classpath (unless there is a CLASSPATH environment variable) is the current directory so if you redefine it, make sure you're adding the current directory (.) to the classpath as I have done.
Ant - javac task - classpath is not taking the jars
You're closing the <javac>
tag on the same line, it should be:
<javac srcdir="${src}" destdir="${dest}">
<classpath refid="classpath"/>
</javac>
Impacts of including too many jar files in classpath
If you depend on these jars, then it's OK. 40 dependencies is not that much, actually, so don't consider that a problem. Just make sure you don't include unused dependencies.
CMD compile using jar files
You can do that using the -classpath
flag.
javac -classpath your.jar:my.jar ...
The delimiter between jars changes according to your platform.
You can read about that by running javac -help
or reading the javac
documentation online and About Setting the Class Path.
You will notice there that the documentation says:
Multiple path entries are separated by semicolons with no spaces
around the equals sign (=) in Windows and colons in Oracle Solaris.
So, all Xnix operating systems use a :
as delimiter, whereas Windows use a ;
.
Adding jar files in each jvm run dont seem to work
You've overridden the classpath, so it only contains the driver. You need to include your current directory there as well.
java -cp postgresql-42.1.4.jar:. myFile
Also please adhere to Java naming conventions. It should be MyFile
, not myFile
.
Related Topics
Simpledateformat Ignoring Month When Parsing
How to Tell Jackson to Ignore a Field During Serialization If Its Value Is Null
What Are Functional Interfaces Used For in Java 8
How to Efficiently Remove Duplicates from an Array Without Using Set
Can Java Finalize an Object When It Is Still in Scope
Java Https Client Certificate Authentication
Number of Lines in a File in Java
Take a Char Input from the Scanner
How to Get a Path to a Resource in a Java Jar File
Calculate Date/Time Difference in Java
How to Generate Exceptions from Repaintmanager
How to Save a String to a Text File Using Java
Can an Abstract Class Have a Constructor
How to Convert Int[] into List≪Integer≫ in Java
How to Set the Environment Variables For Java in Windows
Are Fields Initialized Before Constructor Code Is Run in Java