This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Exception in thread "main"" Watch "Exception in thread "main"" New topic
Author

Exception in thread "main"

Joanne Ho
Greenhorn

Joined: Nov 15, 2005
Posts: 3
I test my program on NetBeans IDE4.1 by calling "Run"->"Run File"->"Run JEMQInterface.java". It runs perfectly ok.

Since NetBeans will automatically built a jar file for my program at the "./dist" directory under my project directory i.e. "c:\JEMQInterface", I tried to run the jar file without using NetBeans by executing the following at command prompt:
>java JEMQInterface

Then it failed to run and produce the exception.

Could anyone help. Thanks.


Exception in thread "main" java.lang.NoClassDefFoundError: JEMQInterface (wrong
name: JEMQInterface/JEMQInterface)
at java.lang.ClassLoader.defineClass0(Native Method)
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$100(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)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
[ November 15, 2005: Message edited by: Joanne Ho ]
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9033
    
  10
To run a jar file, you should type
java -jar JEMQInterface.jar


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12911
    
    3

Exception in thread "main" java.lang.NoClassDefFoundError: JEMQInterface (wrong name: JEMQInterface/JEMQInterface)

There's something wrong with the directory structure in your JAR file. You have a "package JEMQInterface;" statement in your source file, but the class file is in the root inside the JAR file, instead of in a subdirectory JEMQInterface.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Exception in thread "main"
 
Similar Threads
SwingSet3
run jar
Exception Thrown when i try to run a jar file
xxxx.jar seen as xxxx.zip on desktop and won't run
Problem executing jar