Including Jars in Classpath on Commandline (Javac or Apt)

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



Leave a reply



Submit