Aelgawad
Aelgawad

Reputation: 194

Distributing .jar files

I wanted to distribute a .jar file to a layman audience (all windows users). But I can't run the jar file myself unless I do it from cmd using "java -jar "C:\..\file.jar".

When I double click on the file nothing happens (the default program is Java Platform SE Binary). Someone suggested this site but I couldn't follow along in Win8.

So I want the user to be able to double click on the jar file and launch it directly without me telling them to open command prompt and typing stuff, or giving them the link.

PS: it is a very simple non-GUI application. Thanks for your time.

Upvotes: 2

Views: 1028

Answers (2)

janos
janos

Reputation: 124804

I think your best bet is to create a file.bat script that will run the jar, with this simple line in it:

java -jar file.jar

Give the users both files, file.jar and file.bat, and they can double-click on file.bat to run it.

In theory, if the jar file has a manifest in it (META-INF/MANIFEST.MF) with the main class defined in Main-Class: then it should be runnable by double-click. However, you say the app doesn't have a GUI, in which case it will run just fine, but you won't be able to see it.

In any case, the bat file should help, in the worst case users can just run that and not worry about typing java -jar ... etc.

Upvotes: 1

Franz Kafka
Franz Kafka

Reputation: 10851

How did you create the jar file? Jar files have a manifest file inside to, amount others, indicate the location of your main method. Check that this is correct.

You should be able to run the app by double clicking it but it can only be a program with a GUI or a program without direct user interaction.

Upvotes: 1

Related Questions