This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to make up several java file to one *.jar file ? with programing 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 » Java in General
Bookmark "How to make up several java file to one *.jar file ? with programing" Watch "How to make up several java file to one *.jar file ? with programing" New topic
Author

How to make up several java file to one *.jar file ? with programing

filson sun
Greenhorn

Joined: Mar 06, 2011
Posts: 12
Like the title,I have a project with serveral java file, then I want to make up them to one *.jar file with programing.
I have put the serveral java files into one File(AlimonyGather), and use commands "jar cvf A.jar AlimonyGather "
But the A.jar warning that "Failed to load Main-Class".
Tom Reilly
Rancher

Joined: Jun 01, 2010
Posts: 618
If you are using Java 6, you can use the entrypoint flag (e) to specify the main class. Otherwise you will have to create a manifest file in your jar file. Here's a tutorial http://download.oracle.com/javase/tutorial/deployment/jar/appman.html that describes both.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3581
    
  14

First of all, your class path is at the top level. Therefore, you should add your top level package folder to your Jar.
AlimonyGather doesn't look like a package name.

Let's say your main class is com.example.alimony.Main.

Then try this:

jar -cfe A.jar com.example.alimony.Main com/example/alimony
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to make up several java file to one *.jar file ? with programing
 
Similar Threads
How to combine multiple JARs into one JAR
Locating a jar file relative to the application
Setting classpath for Jar file inside jar file
JavaBeans sharing two or more utility classes.
setting classpath for jar file inside jar file