How to set CLASSPATH in Linux to let java find jar file?

后端 未结 4 910
误落风尘
误落风尘 2021-01-07 14:40

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

java -jar plantuml.jar -testdot

while having CLASSPATH set to any of th

4条回答
  •  礼貌的吻别
    2021-01-07 15:12

    The classpath is used to find classes when you refer to them by name. It's essentially a list of paths (directories AND jar/zip files) where the JVM needs to look for classes, or other resources when using methods like ClassLoader.getResourceAsStream().

    The value passed to the -jar option on the command line is the file-path to the JAR file.

    So, it won't find a jar file if you are only referring to the jar file by name. The JAR file path in the CLASSPATH is supposed to be a path element that 'contains' other resources.

    What you need to do here, is either

    1. Provide the full path to the jar file when trying to execute the jar
    2. Set the classpath to the jar file's path, and run the java command giving the name of the main class you want to execute.

提交回复
热议问题