• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

trouble creating jar file

 
Mike Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mike Harris
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15480
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic