Reputation: 462
I am able to use:
C:\Program Files (x86)\Java>javac -classpath mail.jar myFile.java
to compile,but when I try to run it:
C:\Program Files (x86)\Java>java -cp mail.jar myFile
Exception in thread "main" java.lang.NoClassDefFoundError: myFile
Caused by: java.lang.ClassNotFoundException: myFile
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)
Could not find the main class: myFile. Program will exit.
I tried using various combinations using "." and "-classpath" to denote class path as other posts have sugested but couldn't figure it out. I've compiled and successfully run a basic helloworld.java in the same folder. running as admin. using java runtime 1.6.
Upvotes: 0
Views: 860
Reputation: 2481
You need to do one of the following:
pack the jar first (use the jar
command) and use java -jar
not specify a classpath and just run your class file (standalone applications)
(if the jarfile is a library) you need to include the current directory in your classpath
Upvotes: 1
Reputation: 13946
Put your current directory into the classpath as well:
java -cp .;mail.jar myFile
If that doesn't work, post myFile.java
so we can see what might be going on. For example, is myFile
in the default package or is there a package
statement?
Upvotes: 3