File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Passing cmd line arg to Jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Passing cmd line arg to Jar" Watch "Passing cmd line arg to Jar" New topic

Passing cmd line arg to Jar

K. Merritt

Joined: Jun 22, 2004
Posts: 3
I exported my source code to a jar file and moved it to a folder under the cdrive. I can execute the jar on the cmd line by typing name.jar. I can execute the jar specifying java and the classpath. However at no time can I execute AND pass an argument.

I know the syntax is java [-options] -jar Name.jar [args...] but when I add the [args...] to the working syntax I receive the following error:

C:\MQCLient_TM>java -cp C:\ProgramFiles\IBM\WebSphereMQ\Java\lib;C:\Oracle9.2 -jar
c:\MQClient_TM\LCDirectory.jar [kim]
Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/mq/MQExceptio
at net.LCDirectory.EY_LCDirectory.main(EY_LCD

Sorry for the wrapping. Again if I leave off [kim] the line executes but not what I need for my pgm.

Please advise how to execute jar and pass parameter when [args...] not working.

Thank you,

Pavel Kubal
Ranch Hand

Joined: Mar 13, 2004
Posts: 360
Here is example of executing jar file with parameters

java -jar MainFrame.jar first Mabel 25

But it seems, that your jar cannot be executed. I mean problem is somewhere else than in passing params.
Ripan Karmakar

Joined: Jul 28, 2004
Posts: 16
hi pavel,
u r wright.......i have tried with a tiny program....... but the following command does not work:

making jar command:C:\j2sdk1.4.2_03\bin>jar -cvf Char.jar Char.class
[no error]

executing jar file:C:\j2sdk1.4.2_03\bin>java -jar Char.jar
Failed to load Main-Class manifest attribute from

plz anyone help me 2 solve this........


"Strenght is Life and Weakness is Death"<br />Java/J2EE Developer<br />UshaComm Pvt. Ltd, Kolkata, INDIA
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

Ripan: Your problem is different.
You need to add a line:
Main-class: Char

to your Manifest.

But K. tells us, it works, without arguments, but not with.
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9059
Originally posted by K. Merritt:
java -cp C:\ProgramFiles\IBM\WebSphereMQ\Java\lib;C:\Oracle9.2 -jar c:\MQClient_TM\LCDirectory.jar [kim]

Have you tried running without the square brackets on the arg?

[ July 29, 2004: Message edited by: Marilyn de Queiroz ]

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
I agree. Here's the link:
subject: Passing cmd line arg to Jar
It's not a secret anymore!