Two Laptop Bag*
The moose likes Java in General and the fly likes Running Jars Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Running Jars" Watch "Running Jars" New topic
Author

Running Jars

R Hadow
Greenhorn

Joined: May 17, 2004
Posts: 1
I have been experimenting with making my own JAR files.
Some of which work and some don't. After hours of altering the application I haven't been able work out why they sometimes work and sometimes don't.

When the JAR file won't run I get an Exception in thread "Main" java.lang.NoClassDefFoundError ,but at other times
I get an Exception in thread "main" java.lang.ClassFormatError: MyClass (Bad magic number).

I create and run the jar file using the following steps:

1/ I create a manifest file, saved as"info"

Manifest-Version: 1.0
Created-By: 1.4.1_05
Main-Class: MyClass

2/ Create a java file "MyClass.java"
Public MyClass {
public static void main(String args[])
{
System.out.println("MyClass running");
}
}

3/ Create a class file "MyClass.class"
javac Myclass.java

4/ Test the application... java MyClass

5/ Create a Jar file .........jar cmf info MyJar.jar MyClass.class
6/ Run the jar file...........java -jar MyJar.jar

I don't understand why it compiles and runs ok, but i get exceptions thrown when i attempt to run the jar.
I would be very grateful for any help
???

Rob Hadow
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Checkout Dirk's Threads on (executable) jar files.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Jim Tonn
Greenhorn

Joined: Apr 28, 2004
Posts: 4
You seem to be doing everything right. I tried what you are trying and it works fine for me. I get the feeling that you may have some kind of version problems. Are you running a new version of javac but an older version of jar?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running Jars