A bash script for easy and automated execution of Java applications (.jar) in a Linux environment. The script intelligently searches for executable files and handles the availability of the Java Runtime Environment (JRE).
- Automatic JAR Detection: The script automatically finds the first
.jarfile in thedistfolder. - Java Prioritization:
- First, it attempts to use the system-wide Java installation (
command -v java). - If system Java is missing, it tries to run the application using a local JRE located in the
jre_linuxdirectory.
- First, it attempts to use the system-wide Java installation (
- Robust Error Handling: Informs the user if the JAR file or JRE is missing and suggests a solution.
For the script to function correctly, maintain the following structure:
.
├── universal-java-launcher.sh # This script
├── dist/ # Folder containing your .jar file
└── jre_linux/ # (Optional) Local JRE for Linux
- Ensure the script has execution permissions:
chmod +x universal-java-launcher.sh
- Important: If the script was edited on Windows, fix the line endings before running:
sed -i 's/\r$//' universal-java-launcher.sh - Run the script:
./universal-java-launcher.sh
Variables for modifying paths are located at the beginning of the script:
JAVA_DIR: Path to the local JRE.DIST_DIR: Path to the directory with distribution JAR files.
- Linux OS
- Bash shell
- Java JRE (System or Local)