Define libraries without changing Java
It is not recommended to define a classpath
global. May cause unwanted side effects in other programs.
To avoid repetition, create a file shell script containing the commands you need, use the chmod
to set running permissions for the file and use the new "executable" instead of calling Java directly when you need it.
Using the variable CLASSPATH
If you still want to define a classpath
global, the correct is using the environment variable CLASSPATH
. However, change the semicolon by colon in the directory separation, as follows:
export CLASSPATH="dir1:dir2:path/to/jar/containing/AnotherClass:...
Semicolon is used in Windows environments while colon is used in Unix/Linux environments.
Also, if you want the environment variable to be present at all linux sessions, even after system reboot, you will need to add the command export
in some startup script.
Changing the Java installation
As noted in this reply by Soen, you can put the jar in the folder ext
of the Java installation:
JAVA_HOME/jre/lib/ext
Again, I do not advise doing this. Even very common libraries can sometimes generate conflicts. For example, some older project may depend on an older version of the same jar used by a newer application.
Are you making use of any IDE?
– mutlei
No, I use the command line.
– pmargreff