My question is regarding including jar files in path. It has 2 parts.
1) I am trying to execute weka.jar jar file located in /home/andy/software/weka/weka.jar
PATH variable points to this jar file (i.e. to /home/andy/software/weka/weka.jar) and so does CLASSPATH.
However when I try to run the jar using java -jar weka.jar, I get an error "Unable to access jarfile weka.jar".
Any ideas what is going on? I am on Ubuntu Linux. I looked around in SO and it seems like I am not doing anything that is obviously wrong (since both PATH and CLASSPATH seem to be set correctly).
2)I would like to be able to put all my jar files in a single directory and include that directory in my path (instead of including every jar individually). How can I do that?
Thanks in advance.
EDIT 1 -> Here's my command line
andy@laptop:~$ export CLASSPATH=$CLASSPATH:/home/andy/research/software/weka/weka.jar
andy@laptop:~$ echo $CLASSPATH
:/home/andy/research/software/weka/weka.jar
andy@laptop:~$ java -jar weka.jar
Unable to access jarfile weka.jar
andy@laptop:~$ java weka.jar
Exception in thread "main" java.lang.NoClassDefFoundError: weka/jar
Caused by: java.lang.ClassNotFoundException: weka.jar
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: weka.jar. Program will exit.
andy@laptop:~$
EDIT 2 -> I changed PATH variable to point to directory '/home/andy/research/software/weka/' and still get 'unable to access jarfile error'
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With