File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Running Jars" Watch "Running Jars" New topic

Running Jars

R Hadow

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 ""
Public MyClass {
public static void main(String args[])
System.out.println("MyClass running");

3/ Create a class file "MyClass.class"

4/ Test the application... java MyClass

5/ Create a Jar file .........jar cmf info MyJar.jar MyClass.class
6/ Run the jar -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

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:
subject: Running Jars
jQuery in Action, 3rd edition