天天看点

java classpath linux,如何在Linux中设置CLASSPATH让java查找jar文件?

java classpath linux,如何在Linux中设置CLASSPATH让java查找jar文件?

Under Linux I am trying to run a jar file as follows:

java -jar plantuml.jar -testdot

while having CLASSPATH set to any of the following (the file is located at /home/user/plantuml.jar):

export CLASSPATH=/home/user

export CLASSPATH=/home/user/

export CLASSPATH=/home/user/plantuml.jar

In either case, no matter how I define CLASSPATH, the java command gives an error Unable to access jarfile plantuml.jar. What am I doing wrong here?

解决方案

You have to supply the complete path after the parameter -jar. So for your example you have to call

java -jar /home/user/plantuml.jar -testdot

The $CLASSPATH is only evaluated to find additional files (classes/resources) but not the jar file defined in the command line.