-
Notifications
You must be signed in to change notification settings - Fork 3
Convert Java Executable to Linux Executable
Java program is universal and applicable to most operating systems, but if someone intends to create a native executable binary file for certain operation system, is that possible?
The answer is yes. Here is the instruction to create an executable program for Linux with .run
as its extension name.
This instruction fully tested under Ubuntu 14.04 LTS 64-bit, Java 1.8.0_25 64-bit. If any error has been found, feel free to report to Issues.
- Create a text file use your favorite text editor (In this case it is gedit) and type these code below:
#!/bin/sh
MYSELF=`which "$0" 2>/dev/null`
[ $? -gt 0 -a -f "$0" ] && MYSELF="./$0"
java=java
if test -n "$JAVA_HOME"; then
java="$JAVA_HOME/bin/java"
fi
exec "$java" $java_args -jar $MYSELF "$@"
exit 1
save as stub.sh
.
-
Pack your project into a runnable
*.jar
program, which is the native Java executable file. Use Eclipse is recommended. (File -> Export... -> Runnable JAR File) Pack the necessary Java Library is also recommended. Export the*.jar
file in the same directory ofstub.sh
. -
Run the command below, make sure the current directory is the same one includes
stub.sh
and the*.jar
file.
cat stub.sh PROJECT.jar > PROJECT.run && chmod +x PROJECT.run
where PROJECT
is the name of your *.jar
file.
- That's all! after this you will have a file named
PROJECT.run
and you could run it via./PROJECT.run
orsh PROJECT.run
. Furthermore, all arguments are supported as the original Java executable file.