如何在Linux中设置CLASSPATH让java查找jar文件? [英] How to set CLASSPATH in Linux to let java find jar file?
问题描述
在Linux下我试图运行一个jar文件,如下所示:
Under Linux I am trying to run a jar file as follows:
java -jar plantuml.jar -testdot
将 CLASSPATH
设置为以下任何一项(该文件位于 /home/user/plantuml.jar
):
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
在任何一种情况下,无论我如何定义 CLASSPATH
, java
命令给出错误无法访问jarfile 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?
推荐答案
你必须在参数 -jar之后提供完整的路径
。因此,对于您的示例,您必须致电
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
仅评估 $ CLASSPATH
以查找其他文件(类/资源)但不是命令行中定义的jar文件。
The $CLASSPATH
is only evaluated to find additional files (classes/resources) but not the jar file defined in the command line.
这篇关于如何在Linux中设置CLASSPATH让java查找jar文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!