Ubuntu下IntelliJ构建的Artifact无法运行问题求助
Hey there, let's troubleshoot why your JavaFX JAR won't run on Ubuntu 16.04. I've dealt with similar issues plenty of times, so let's break this down step by step:
Double-clicking a JAR hides critical error messages, which are key to figuring out what's wrong. Open a terminal, navigate to your JAR's folder with cd /path/to/your/jar/folder, then run:
java -jar your-app-filename.jar
Note the exact error output—this will point us directly to the root cause.
1. Missing Executable Permissions
Ubuntu might block the JAR from running due to insufficient permissions. Fix this by running:
chmod +x your-app-filename.jar
Try double-clicking again, or re-run the command line command above.
2. Missing JavaFX Runtime Dependencies
Ubuntu 16.04's default OpenJRE (even version 9) often excludes JavaFX modules. Here's how to fix this:
- Install the OpenJFX package via apt:
sudo apt-get update && sudo apt-get install openjfx - If you're using a modular JavaFX app, you'll need to specify the module path when running. First, download the JavaFX SDK matching your JRE 9 version, then run:
Replacejava --module-path /path/to/javafx-sdk-9/lib --add-modules javafx.controls,javafx.fxml -jar your-app-filename.jar/path/to/javafx-sdk-9/libwith the actual path to your SDK's lib folder.
3. Incorrect Main Class Configuration in Artifact
Head back to IntelliJ's Project Structure > Artifacts and double-check:
- You've selected the correct main class (the one that extends
javafx.application.Application). - The generated
META-INF/MANIFEST.MFfile inside the JAR has the right entries. It should include:
(Some JavaFX versions require both lines to launch properly.)Main-Class: com.your.package.YourMainClass JavaFX-Main-Class: com.your.package.YourMainClass
4. Incorrect JAR File Association in Ubuntu
Sometimes Ubuntu uses the wrong JRE to open JARs. Fix this:
- Right-click your JAR file > Properties > Open With
- Select your installed JRE 9's
javaexecutable (avoid generic "OpenJDK" entries if they lack JavaFX) - Check "Use this application to open all .jar files" and save.
- Try rebuilding your artifact from scratch in IntelliJ: Go to Build > Build Artifacts > Build to ensure no hidden build errors slipped through.
- JRE 9 is pretty outdated—consider upgrading to JRE 11 or later (Ubuntu 16.04 supports these) for better JavaFX compatibility, since JavaFX became a separate module starting with JRE 11.
内容的提问来源于stack exchange,提问作者user1300214

