Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cant make a .jar 1

Status
Not open for further replies.

rs51

Technical User
Oct 13, 2001
163
PT
i googled and searched for this item but coudnt find help
here's what i've:
a simple class Adivinha.class that compiles and runs perfectly

i wrote a m.txt (manifest) saying:

Main-Class: Adivinha.class

and inserted a new line at the end.
from the same dir, i made:
command line>jar cmf m.txt a.jar Adivinha.class

when i click on the .jar i get this error msg:
Could not find the main class. The program will exit.

note: i tried the same with a helloworld.class too
What am i doing wrong?
 
What does your Table of Contents look like on the JAR file? You can check using:
> jar tf a.jar

When you have created your JAR file, how are you running it? Are you using:
> java -jar a.jar

Pete.


Lotus Notes Web Developer / Aptrix (LWWCM) Consultant
w: e: Pete.Raleigh(at)lclimited.co.uk
 
thanks for your answer
i get this:
META-INF/
META-INF/MANIFEST.MF
Adivinha.class
I'd like to open the jar with double click
i've win xp pro, all updates and jsdk1.4.2_03
 
if i use your command to read the jar, i get this:

dos dir>java -jar a.jar
Exception in thread "main" java.lang.ClassFormatError: Adivinha (B
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Sou
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 Meth
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Sour
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
 
Part of the error message appears to be truncated - what is the full error message?

Pete.


Lotus Notes Web Developer / Aptrix (LWWCM) Consultant
w: e: Pete.Raleigh(at)lclimited.co.uk
 
sorry
"Exception in thread "main" java.lang.ClassFormatError: Adivinha (Bad magic number)"
 
Try recompiling your class file and make sure everything is ok. You'll often run into this problem if you view classes through a decompiler and then try to run.

Try also creating a directory called "a" (the name of your JAR file) and storing your class file in that before creating the JAR.

You should then end up with something like:
META-INF/
META-INF/MANIFEST.MF
a/
a/Adivinha.class

Pete.


Lotus Notes Web Developer / Aptrix (LWWCM) Consultant
w: e: Pete.Raleigh(at)lclimited.co.uk
 
In first place i have to thank you again for your continued help

Now i made this:
i've a dir called: a
inside i have this file: HelloWorldApp.java
public class HelloWorldApp {
public static void main(String[] args) {
// escreve "Viva, Cosmos!"
System.out.println("Viva, Cosmos!");
}
}
Then i compiled and got the HelloWorldApp.class
>java HelloWorldApp
returns:
Viva, Cosmos!
So, so far, all is well

Now, inside this dir (a), i have this MANIFEST.MF:
Main-Class: HelloWorldApp
(with a new line enter after the end of text)

After i made this:
a>jar cmf MANIFEST.MF a.jar HelloWorldApp.class

now, if i make:
>jar tf a.jar,
i get this:
META-INF/
META-INF/MANIFEST.MF
HelloWorldApp.class

then, i make this:
>java -jar a.jar,
and get this:
Viva, Cosmos!

So i guess everything is now ok.
I changed the file because with Adivinha gave me strange errors; i'm gonna try with the later and be back if something wrong happens;
Of course if i double click my new jar nothing happens - is this normal? I guess so
Thanks a lot once again!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top