Add something to the java classpath
I have a jar-File, which I want to add to the classpath, so I ran java -cp ".;C:Pathtomymagicaljarfile.jar;.someotherdirectory" MyClass
The Problem is: I use some import-commands in my class, an Java doesn’t find them anymore, because I replaced the classpath. I want just add two elements to the Path. How is this posible under Windows?
Solution – 1
The default class path is the current directory. Setting the CLASSPATH variable or using the -classpath command-line option overrides that default, so if you want to include the current directory in the search path, you must include "." in the new settings.
So, to add to that default, include the CLASSPATH environment variable in your invocation:
java -cp ".;C:Pathtomymagicaljarfile.jar;.someotherdirectory;%CLASSPATH%"