Problem with JAR file

Hi guys, I created one calculator in Java and it runs fine in my pc. But now I want to send it to my professor so that he can view it by just a mouse click.

So, I created one JAR file. But when I click the JAR file I always get the following message " Failed to load Main-class manifest attribute from C...........atiq.jar

For you some info:

1. The name of my main class is Namer that extends JFrame

2. I have 2 inner classes as ButtonListener and ComboListener inside

main class

3. In Manifest.mf file it's written : Main-Class: Namer

4. In a folder I have put jar.exe, all class files, Namer.java and Manifest.mf file

5. I wrote the following code to make the jarjar cfm atiq.jar Manifest.mf Namer.java *.class

6. The atiq.jar file is created but when I click this icon, my program doesn't run and I get the above error.

Plz help me out .....

[922 byte] By [atiq761a] at [2007-11-26 20:20:27]
# 1

You can't just dump all your .class and whatever files in a .jar file and

expect the jvm to figure out what class to use for the main(...) method.

You have to add a little file, named 'Manifest.mf' in a directory 'meta-inf'

which contains at least this:

Main-Class: YourClassThatContainsAMainMethod

I'm about sure that other kind people will supply you with the links to

some tutorials w.r.t. the 'jar' command if you can't find them yourself.

kind regards,

Jos

JosAHa at 2007-7-10 0:44:56 > top of Java-index,Java Essentials,New To Java...
# 2

All you need to do is create a text-file (e.g. Manifest.txt) and add the line

Main-Class: yourpackage.YourClass

to it, AND add a newline at the end of the text-file. Then use the command

jar cmf Manifest.txt JarName.jar yourpackage/*.class

provided you have the Manifest.txt file in the current directory and the .class files in a subdirectory named yourpackage (i.e. your class belongs to a package named yourpackage).

#

duckbilla at 2007-7-10 0:44:56 > top of Java-index,Java Essentials,New To Java...
# 3
Hi guys, thanks for your replies. I followed duckbill's instructions and it works perfectly now. Thanks.
atiq761a at 2007-7-10 0:44:56 > top of Java-index,Java Essentials,New To Java...