• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Running Jars

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Checkout Dirk's Threads on (executable) jar files.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
reply
    Bookmark Topic Watch Topic
  • New Topic