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

Executing a java program from a jar

Gsan Sangle
Greenhorn

Joined: May 23, 2006
Posts: 3
Hi all,
I have a the following question :
i have a class that is wrapped up in a jar , the class has a main method.
the manifest file does not contain the "MainClass :" entry.
i want to exeute the class with main function.
Can any help me ?


Trying to Learn
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

java -jar myjar.jar myclass
(Make sure the CLASSPATH is set properly)


[My Blog]
All roads lead to JavaRanch
Gsan Sangle
Greenhorn

Joined: May 23, 2006
Posts: 3
my jre/bin folder does not contain the .java file...
how do i set the path var, n wat exactly should be it be set to ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Let's say your JAR file is called "myjar.jar".
Let's say the class containing your main method is called "MyClass.class"

1. Go to the directory where myjar.jar is
2. Execute : java -cp . -jar myjar.jar MyClass

This will launch MyClass contained in myjar.jar
You don't need the java file.
Gsan Sangle
Greenhorn

Joined: May 23, 2006
Posts: 3
Got the following error :

Failed to load Main-Class manifest attribute from
c:\extJars\abc_classes.jar

The manifest file does not contain the req entry.
Can it still be executed without the entry ?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

Oops sorry, I misread your post.
Yes, I think you'll have to add this entry into the manifest file.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3446
    
  12
If you don't have a MainClass entry in your manifest you can't use the -jar option. Just add the jar file to your class path.

java -cp myjar.jar MyClass


Joanne
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Executing a java program from a jar