aspose file tools*
The moose likes Java in General and the fly likes java -jar XXX does nothing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "java -jar XXX does nothing" Watch "java -jar XXX does nothing" New topic
Author

java -jar XXX does nothing

jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
Hi Guys : I exported a Jar from eclipse, and then, by issuing the command

java -jar package.MyMainClass

I expected to see some output, however, nothing happened.

What does this mean ? Does this mean that

1) The jar command is failing due to bad syntax --- I assume this is NOT the case ?

or

2) The jar command syntax valid, but for some reason, it does not call the main method in my class.

Thanks for any feedback.

PS I have tried exporting the jar with and without a defined executable run class...

here is the jar creation script description below

jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
The strange thing is, however, that I CAN integrate this jar into an application and use it, perfectly.... i just cant invoke its services via that "java -jar xxx" method..... Ive never noticed anything like this.... I wonder if there an "Executable" attribute to jars or something, that can be turned on or off via some type of configuration ???
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

No, you were right with your first guess, though you assumed you weren't. Correct syntax is:

java -jar venn3_core.jar

which will run jmolwrap.JayMolScript (assuming there is a main method there)

or

java -cp venn3_core.jar:$CLASSPATH package.MyMainClass

jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
I'm sorry I tried java -jar xxx.jar ClassName and tha failed. My first post was a typo.....
The command has no effect. Very strange .!!!
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2864
    
  11

Well, again, java -jar jarfile ClassName isn't correct syntax either, but it's closer. That should run the main class defined in your manifest file and pass it ClassName as an argument ... an argument it most likely won't understand though. If you think that command should be running the ClassName class, you're probably going to be disappointed.
Joanne Neal
Rancher

Joined: Aug 05, 2005
Posts: 3742
    
  16
jay vas wrote:I'm sorry I tried java -jar xxx.jar ClassName and tha failed. My first post was a typo.....
The command has no effect. Very strange .!!!


Any class name specified on the command line when using the -jar option is ignored. As Greg said, when you use the -jar option the main method that will be run is the one in the class specified in the Main-Class entry in your jar's manifest file which, in your case, is jmolwrap.JayMolScript. If this is wrong then you need to change your manifest file.


Joanne
jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
Thats strange that you cannot run a main class of your choosing when invoking via the java -jar command .... is there any reason why this is the case ? It seems only natural that invocations of a "java -jar" command might require, in certain circumstances, the use of a different main class . At the very least, I wouldnt be surprised if people have requested this feature in the past ?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

jay vas wrote:Thats strange that you cannot run a main class of your choosing when invoking via the java -jar command .... is there any reason why this is the case ? It seems only natural that invocations of a "java -jar" command might require, in certain circumstances, the use of a different main class . At the very least, I wouldnt be surprised if people have requested this feature in the past ?


That is how it is defined... When you use the -jar option, it gets the main class from the manifest. If you don't want to use the class specified in the manifest, then use the -cp option, and specify the main class.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
jay vas
Ranch Hand

Joined: Aug 30, 2005
Posts: 407
Okay.... well then for clarity, I guess there is an EXCEPTION to Joann's comment 'when you use jars, any Class Name is ignored', which is that the "cp" flag causes the java -jar command to pay attention to a class name you specify at the end, and use that class as the main class, regardless of what is in the manifest.

For beginners : Java -jar -cp com.mypackage.hello.HelloWorld will run HellWorld.

Thanks guys for all your help my issue is resolved........


Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  40

jay vas wrote:Okay.... well then for clarity, I guess there is an EXCEPTION to Joann's comment 'when you use jars, any Class Name is ignored', which is that the "cp" flag causes the java -jar command to pay attention to a class name you specify at the end, and use that class as the main class, regardless of what is in the manifest.


It is not an EXCEPTION, you are not supposed to mix the -jar and -cp options. If you want to specify a class that is in a jar file, then you use -cp to specify the jar file, and you also need to specify the class.\

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java -jar XXX does nothing