How to execute a java program with external jar
external, jar, java
Solution
I think what you want is:
java -cp myPackages/guava-13.0.jar:. MyScanner
Notice I'm setting two values in the classpath, '.' (current directory) and the path to guava. Your problem is that you specified the classpath option after you specified your main class `MyScanner`. Options that are specified after your main class are arguments to your program, not to java itself.
Problem
I want to run my program with guava. If I compile my program with EDIT: java -> javac for the compile call ``` javac -cp myPackages/guava-13.0.jar MyScanner.java ``` there is no problem. If I try to run ``` java MyScanner -cp myPackages/guava-13.0.jar ``` I get this output on the console: ``` Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/base/Optional at MyScanner.main(MyScanner.java:37) Caused by: java.lang.ClassNotFoundException: com.google.common.base.Optional at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) ... 1 more ``` Can you tell me how I can execute the program with the external jar?