There was a program that I used that made runnable .jar files.. All the ones I'm finding now are ones that make .exe files.. I remember it also has the option to make the file a .sh script as well. Anyone knows its name? I've been searching for hours with no avail :/
-
You don't need a program to make runnable .jar files. You just need to have Main-Class: defined in the META-INF/MANIFEST.MF file inside the jar. Why would the .sh script need more than java -jar Foo.jar ? – Talon876 Jul 06 '12 at 04:03
-
Possible duplicate: (1) ***[How to make an executable jar file?](http://stackoverflow.com/questions/5258159/how-to-make-an-executable-jar-file)*** (2) ***[making a jar file for console](http://stackoverflow.com/questions/4497579/making-a-jar-file-for-console)*** (3) ***[How can I create an executable jar with dependencies using Maven?](http://stackoverflow.com/q/574594/1164465)*** (4) ***[Build an executable jar file with Ant tool](http://stackoverflow.com/q/5959463/1164465)*** (5) ***[Eclipse: How to build an executable jar with external jar?](http://stackoverflow.com/q/502960/1164465)*** – Christopher Peisert Jul 06 '12 at 04:16
4 Answers
The command line
java -jar file.jar
Will run your jar file if it has a Main-Class
defined as explained here.
You can use that command in a shell script.

- 7,273
- 4
- 32
- 55
You can create a runnable jar using NetBeans IDE or Eclipse IDE by just providing the main class to run. Rest of the things it will take automatically. That class must be having a main()
method in it. Then you can run that jar file using java -jar yourjarfile.jar

- 100,966
- 191
- 140
- 197

- 9,776
- 6
- 41
- 66
Do you mean actually coding java and then compiling to .jar? If you do try eclipse code editor
I used eclipse to make minecraft mods. It will work if you want to make .jar programs.

- 3,503
- 3
- 29
- 42
-
I'm using eclipse! The problem is that I'm using native libraries which Eclipse isn't putting into the jar correctly. – Patokun Jul 06 '12 at 04:18
If you want to have a jar that you can execute using the usual syntax ./app.jar
(instead of java -jar
), here is a post explaining the process: how to create executable jars.
Basically, JAR is a variant of ZIP, which allows random bytes to be pre/appended to the JAR without corrrupting it. This means it is possible to prepend a launcher script at the beginning of the jar to make it "executable".
Here is a simple example of the process:
# Append a basic launcher script to the jar
cat \
<(echo '#!/bin/sh')\
<(echo 'exec java -jar $0 "$@"')\
<(echo 'exit 0')\
original.jar > executable.jar
# Make the new jar executable
chmod +x executable.jar
With this, you can now run ./executable.jar
instead of java -jar original.jar
. This works on all unix like systems including Linux, MacOS, Cygwin, and Windows Linux subsystem.

- 9,572
- 2
- 32
- 53