Java 10可执行文件安装后无法正常运行问题求助
Hey there, let's troubleshoot this frustrating JavaFX startup issue you're facing after upgrading to Java 10. I've dealt with similar problems when moving from Java 8 to the modular Java versions, so here are the most common fixes to try:
First, capture startup logs to see what's breaking
The biggest issue here is that you can't see why the exe crashes immediately. Modify your Inno Setup script to redirect the program's output to a log file. Update theParametersline in your icon or shortcut configuration to:Parameters: "--module your.module.name/your.main.class > {app}\startup.log 2>&1"Run the exe again, then check the
startup.logfile in your app's installation directory. This will reveal exactly what's going wrong—missing modules, classpath errors, or runtime exceptions. This step is critical because it turns a "black box" problem into something you can debug.Verify your module system setup
Java 10 uses the module system, which wasn't required in Java 8. If you didn't add amodule-info.javafile when upgrading, that's probably a key issue. Your module descriptor needs to declare dependencies on the JavaFX modules your app uses, and export/open the necessary packages. Example:module com.yourcompany.yourapp { requires javafx.controls; requires javafx.fxml; // Remove if you don't use FXML opens com.yourcompany.yourapp.views to javafx.fxml; // For FXML controller access exports com.yourcompany.yourapp; // Expose your main class package }Also, double-check your
javafx-maven-pluginconfiguration in pom.xml. For Java 10+, you need to specify themoduleNameand ensure thejlinkgoal is properly configured to build a self-contained runtime image.Fix your Inno Setup script's runtime path
If you're using a custom runtime image created withjlink(which is recommended for Java 9+), make sure your Inno Setup script points to the correctjavaw.exeinside the bundled runtime. Avoid relying on the system's Java installation—use the runtime you packaged with your app. Example shortcut configuration:[Icons] Name: "{group}\Your App"; Filename: "{app}\runtime\bin\javaw.exe"; Parameters: "--module com.yourcompany.yourapp/com.yourcompany.yourapp.MainApp"If you're not using
jlink, ensure the Java path in your script points to a Java 10+ runtime that includes JavaFX (Java 10 is the last JDK with JavaFX bundled, so double-check your runtime includes all required libraries).Update your JavaFX Maven plugin to a compatible version
Old versions of the JavaFX Maven plugin designed for Java 8 won't handle the module system correctly. Make sure you're using a version that supports Java 10+. Your pom.xml should include something like:<plugin> <groupId>org.openjfx</groupId> <artifactId>javafx-maven-plugin</artifactId> <version>0.0.8</version> <configuration> <moduleName>com.yourcompany.yourapp</moduleName> <mainClass>com.yourcompany.yourapp.MainApp</mainClass> </configuration> <executions> <execution> <id>jlink</id> <goals> <goal>jlink</goal> </goals> </execution> </executions> </plugin>Also, confirm that your JavaFX dependencies are using the correct platform classifier (
winfor Windows) if you're pulling them from Maven Central.Check third-party library compatibility
If your app uses external libraries, some might not be modularized or might have issues with Java 10's module system. The startup log you captured earlier will show if there are errors like "package X is not accessible". For those cases, you might need to add--add-modulesor--add-exportsparameters to your startup command. For example:Parameters: "--module com.yourcompany.yourapp/com.yourcompany.yourapp.MainApp --add-exports java.base/sun.nio.ch=ALL-UNNAMED"But try to use this as a temporary fix—preferably, update the library to a version that's compatible with Java 9+.
Start with the log capture step first—it will give you concrete info to narrow down the problem. Let me know what the log shows if you need more help!
内容的提问来源于stack exchange,提问作者FunkSoulBrother

