"Could not find the main class: MineAvtaler. Program will exit." - Only when running outside Eclipse
I've made my application in Eclipse. It's fairly simple and contains ~1000 lines total with code. My class MineAvtaler
contains my main function.
I run this successfully from Eclipse's "Run" button. However whenever I try to run the code from command line, I get the error message in the title. I've compiled as such: javac MineAvtaler.java Avtaledata.java Avtale.java
And tried to run the application as such:
- java MineAvtaler
- javaw MineAvtaler.java
The latter gives the error message in a message box instead of in the console.
Why won't my program run outside of Eclipse?
I'm using Windows 7 and have JDK installed. This is the stacktrace I get:
C:\Users\Codemonkey1991\Desktop\mineavtaler>java MineAvtaler Avtaledata Avtale
Exception in thread "main" java.lang.NoClassDefFoundError: MineAvtaler (wrong name: mineavtaler/MineAvtaler)
at java.lang.Cla开发者_运维百科ssLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: MineAvtaler. Program will exit.
*Here is the source code: *
- MineAvtaler.java
- Avtaledata.java
- Avtale.java
It's a problem of packages. MineAvtaler
is inside a package named mineavtaler
(character capitalization is relevant), like stated in the first line of your source. So you probably have a directory called mineavtaler
, created for you by Eclipse. This is not the directory you created for the project, is a 'special' directory created by Eclipse in which it put your MineAvtaler.java
file.
You don't have to open a terminal here. Instead, open it on the parent directory and run: java mineavtaler.MineAvtaler
. This way it should work.
EDIT: run java mineavtaler.MineAvtaler
from C:\Users\Codemonkey1991\Desktop\
When calling the "java" command you always have to observe the package structure. See http://download.oracle.com/javase/tutorial/java/package/packages.html for more info.
精彩评论