aspose file tools*
The moose likes Beginning Java and the fly likes trouble creating jar file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "trouble creating jar file" Watch "trouble creating jar file" New topic
Author

trouble creating jar file

Mike Harris
Greenhorn

Joined: Oct 13, 2005
Posts: 5
I keep getting a "Can't find main class. Program will exit".

This is what I have:

Copy.java has been compiled to copy.class. Here is the source code:




I wrote a custom manifest file that has these lines of code:

Manifest-version: 1.0
Main-Class: Copy
Created-By: 1.4.2_09 (Sun Microsystems Inc.)

I used windows command line to compile, using this:
jar cmf c:\Manifest.mf c:\Copy.jar C:\Copy.class

Please help!
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
When do you get that error? Does it happen when you run the jar program to create the jar file or when you try to run the program after you created the jar file?

Layne


Java API Documentation
The Java Tutorial
Mike Harris
Greenhorn

Joined: Oct 13, 2005
Posts: 5
I get the error after I have created the jar file and I try to execute the .jar
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14156
    
  19

> jar cmf c:\Manifest.mf c:\Copy.jar C:\Copy.class

Try this:

jar cmf c:\Copy.jar c:\Manifest.mf C:\Copy.class

(the name of the JAR file first, then the manifest file).

How are you trying to run your JAR? I guess with this:

java -jar Copy.jar


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Once you create a jar file, run the following command:

jar tf Copy.jar

This will show the contents of the jar file so you can verify that it contains the files you expect.

Also, we need to know how you execute the jar file? Do you use the command that Jesper gave above?

Layne
 
Don't get me started about those stupid light bulbs.
 
subject: trouble creating jar file