Define libraries without changing Java
Setting% global% is not recommended. It can cause unwanted side effects in other programs.
To avoid repetition, create a shell script file containing the commands you need, use classpath
to set execute permissions for the file and use the new "executable" instead of calling Java directly when you need it.
Using the variable chmod
If you still want to set% global%, the correct is using the environment variable CLASSPATH
. However, replace the semicolon with a colon by separating directories, as follows:
export CLASSPATH="dir1:dir2:path/to/jar/containing/AnotherClass:...
The semicolon is used in Windows environments while the colon is used in Unix / Linux environments.
In addition, if you want the environment variable to be present in all Linux sessions, even after rebooting the system, you will need to add the classpath
command to some boot script.
Changing the Java installation
As noted in this SOen response , you can place the jar in the CLASSPATH
folder of the Java installation: / p>
JAVA_HOME/jre/lib/ext
Again, I do not advise doing this. Even very common libraries can sometimes generate conflict. For example, some older project may depend on an older version of the same jar used by a newer application.