Jayanga Kaushalya
Jayanga Kaushalya

Reputation: 2744

Running JAR in Console

I have created program that takes input from System.in and output to System.out. I create the executable jar and I want to run it without entering java -jar in windows. Is there any way to do this?

Upvotes: 0

Views: 123

Answers (4)

maerics
maerics

Reputation: 156612

You use the "start" command like "C:\> start myJarFile.jar".

Upvotes: 0

Dan W
Dan W

Reputation: 5782

You could write a .bat script that will start your jar.

Upvotes: 1

Chris Thompson
Chris Thompson

Reputation: 35598

There are a number of ways to do this. The simplest way is to create a batch (.bat file) file that invokes it for you. There are also a number of solutions out there that will create a Windows executable from a jar file. Note: these programs don't compile the byte code, they just create an executable wrapper around the jar. One option is Jar2Exe but there are quite a few. JSmooth is another option I have used before that works quite well. Another advantage to a program like this is you can bundle all dependent jars into the same executable file as well. Some google searching for "jar to exe" should find you one that works for your solution.

Upvotes: 1

talnicolas
talnicolas

Reputation: 14053

On windows a simple double-click on the jar file should open it if the environment is well set.

Upvotes: 0

Related Questions