Unable to execute jar file despite having PATH and CLASSPATH set

被刻印的时光 ゝ 提交于 2019-12-05 08:42:58

1) -jar option of java disables the use of CLASSPATH. Please take a look at Setting the CLASSPATH of Weka

2) Class path entries can contain the basename wildcard character , which is considered equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For example, the class path entry foo/ specifies all JAR files in the directory named foo. A classpath entry consisting simply of * expands to a list of all the jar files in the current directory. Have a look at Setting the class path|Understanding class path wildcards

You do not execute as

 java -jar weka.jar

Instead you give name of one of the classes INSIDE jar.

a simple example without setting classpath :

 java -jar /home/andy/research/software/weka/weka.jar weka.core.SystemInfo

a simple example using set classpath:

 export CLASSPATH=$CLASPATH:/home/andy/research/software/weka/weka.jar

 java weka.core.SystemInfo

More complicated example:

export WEKA_HOME=/home/andy/research/software/weka/

export CLASSPATH=$CLASPATH:$WEKA_HOME/weka.jar

export HEAP_OPTION=-Xms4096m -Xmx8192m
export JAVA_COMMAND=java $HEAP_OPTION

$JAVA_COMMAND weka.core.SystemInfo

When the jar is in the classpath it means that the library is available to the jvm. When you want to run a jar file (execute it's main), you still need to provide a valid path to the file.

Unable to access *.jar means that java cannot find this jar file. You should either run this command (java -jar weka.jar) from folder where your jar is located, or correct your PATH variable. It should point to the FOLDER where the jar is placed, not the jar file directly.

assuming your in the same folder as the weka.jar all you need is ./ before the jar name

java -jar ./weka.jar weka.core.SystemInfo
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!