Question

I wrote some Java code that takes several arguments using Eclipse. I was able to compile and execute the code just fine by entering the arguments in the "Run configurations."

However, I need to be able to run my code via command-line. This is what I tried:

javac -g ./MyCode.java
java MyCode ./fileOne.txt ./fileTwo.txt ./fileThree.txt

And the error message:

Exception in thread "main" java.lang.NoClassDefFoundError: mypackage/MyCode
Caused by: java.lang.ClassNotFoundException: mypackage.MyCode
    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:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

I don't understand what is going on. My code does not have any bugs when I run through Eclipse. Help?

Was it helpful?

Solution

You are not setting up the classpath properly. http://docs.oracle.com/javase/tutorial/essential/environment/paths.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top