I have project which includes external jar file in it, I followed this link http://www.wikihow.com/Add-JARs-to-Project-Build-Paths-in-Eclipse-%28Java%29 to add external java path. Then I tried to compile my code in terminal, however I am still get an error about jar file does not exist.
I wrote the following commands: (Currently I am in the project directory and there are three folders called bin src and lib in there)
bash-3.2$ ls
bin lib README.txt src
bash-3.2$ javac -cp lib/jsoup-1.6.1.jar src/DayTradingStockBlog.java
bash-3.2$ java -cp .:lib/jsoup-1.6.1.jar src/DayTradingStockBlog
Exception in thread "main" java.lang.NoClassDefFoundError: src/DayTradingStockBlog (wrong name: DayTradingStockBlog)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
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: src/DayTradingStockBlog. Program will exit.
How should I solve this problem ?
You never use slashes, which are path delimiters, in a call to java (but to javac). If src is part of your package declaration – in this case the whole package declaration, which I bet it is not, you would, instead of:
use a dot:
But I guess it is just the place where you created the class, so the path belongs to the classpath:
You aren’t free to omit the path from the Class name, and append it to the classpath, or vice versa – it has to fit to your package declaration.
If you declare a package
foo, (which has much more sense than src), your class name is no longerDayTradingStockBlogbutfoo.DayTradingStockBlog.