wood burning stoves 2.0*
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "trouble creating jar file" Watch "trouble creating jar file" New topic

trouble creating jar file

Mike Harris

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?


Java API Documentation
The Java Tutorial
Mike Harris

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: 14074

> 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?

I agree. Here's the link: http://aspose.com/file-tools
subject: trouble creating jar file
Similar Threads
trying to read from a file and write to a file..but..
I suddenly can't make instances of 'File'
program reagarding reading and writing to a file in java
Copy file
File Reading Error