tags:

views:

575

answers:

4

I am created jar file.The jar file is an executable one.But how can i run the jar file from the out side,using created batch file.I want to know the batch file coding to run the jar file without mentioning class path. Or is there any way to do it?

A: 

If double-clicking the .jar file in Windows Explorer works, then you should be able to use this:

start myapp.jar

in your batch file.

The Windows start command does exactly the same thing behind the scenes as double-clicking a file.

RichieHindle
It gives the error windows cannot find myapp.jar(my jar file).
Arivu2020
@Arivu2020: Are you in the right directory? Perhaps your batch file need to do `cd c:\path\to\my\stuff` before trying to run the jar file?
RichieHindle
A: 

Just the same way as you would do in command console. Copy exactly those commands in the batch file.

BalusC
A: 

To run a .jar file from the command line, just use:

java -jar YourJar.jar

To do this as a batch file, simply copy the command to a text file and save it as a .bat:

@echo off
java -jar YourJar.jar

The @echo off just ensures that the second command is not printed.

mdm
`@echo ...` is only for windows...
Carlos Heuberger
@Carlos: I assumed that as the OP asked for a batch file, that they were using Windows.
mdm
just a note ...
Carlos Heuberger
I am tried .But it is not working
Arivu2020
@Arivu: Not working how?
mdm
I am using windows 7.I have the jar file in the D:\my.jarI write the following code in my batch file@echo offjava -jar my.jar and also i tried@echo offjava -jar D:\my.jarwhat can i do?
Arivu2020
+1  A: 

If you want a batch file to run a jar file, make a blank file called runjava.bat with the contents:

java -jar "C:\myjarfile.jar"
Jonno_FTW