You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Java15+JavaFX15非模块化Shaded Jar通过jpackage打包后安装运行报错求助

Solution for jpackage Missing Module Class Error

Hey, let's break down your problem and fix it. I've dealt with similar jpackage issues with non-modular jars before, so here's what's going on and how to resolve it:

The core issue is that your non-modular shaded JAR runs fine directly because the JDK automatically resolves transitive module dependencies (like java.naming) for non-modular code. But jpackage doesn't do this automatically—it only includes a minimal set of core modules unless you explicitly tell it to include more. That's why you're seeing the javax.naming.NamingException missing error after installation.

Here are actionable solutions, ordered from quick fixes to long-term best practices:

1. Explicitly Include All Required Modules in jpackage Command

When using jpackage without a custom jlink runtime, you need to pass all modules your app depends on (from your jdeps output) via the --add-modules flag. Don't stop at just JavaFX modules—include the system modules too.

Try this command:

jpackage --type pkg \
  --input /Users/johnallen/Downloads/input \
  --main-jar modsim-1.0-SNAPSHOT.jar \
  --module-path /Users/johnallen/Downloads/javafx-jmods-15.0.1 \
  --add-modules javafx.controls,javafx.fxml,java.base,java.compiler,java.desktop,java.instrument,java.management,java.naming,java.scripting,java.security.jgss,java.security.sasl,java.sql,jdk.jfr,jdk.unsupported \
  --name ModSim \
  --main-class org.crob.App

This forces jpackage to include all necessary modules in the bundled runtime, so your non-modular JAR can access classes from java.naming and others.

If you prefer using your pre-built jlink runtime, make sure jpackage uses it correctly and passes the necessary module flags to the JVM:

  • First, verify your jlink runtime actually includes java.naming:
    /Users/johnallen/Downloads/jd15fx15modsimruntime-mvn-ver/bin/java --list-modules | grep java.naming
    
    You should see java.naming@15.0.1 in the output.
  • Then, use this jpackage command to bundle your app with the runtime, and explicitly add module access via --java-options:
    jpackage --type pkg \
      --input /Users/johnallen/Downloads/input \
      --main-jar modsim-1.0-SNAPSHOT.jar \
      --runtime-image /Users/johnallen/Downloads/jd15fx15modsimruntime-mvn-ver \
      --name ModSim \
      --main-class org.crob.App \
      --java-options "--add-modules java.naming"
    
    The --java-options ensures the JVM loads the java.naming module when launching your non-modular JAR.

3. Convert to a Modular App (Long-Term Fix)

Non-modular JARs are prone to these dependency gaps with jlink/jpackage. Converting your app to a modular one will make dependency handling automatic and eliminate this issue entirely:

  1. Create a src/main/resources/module-info.java file:
    module org.crob.modsim {
        requires javafx.controls;
        requires javafx.fxml;
        requires mongo.java.driver;
        requires morphia.core;
        requires hedera.hashgraph.sdk;
        requires grpc.netty.shaded;
        
        exports org.crob;
        opens org.crob to javafx.fxml; // Needed for FXML controller reflection access
    }
    
  2. Update your Maven setup:
    • Adjust the maven-compiler-plugin to target Java 15 (aligning with your OpenJDK 15 runtime) instead of 11.
    • You can remove the Maven Shade plugin if you don't need to bundle dependencies, or use the Moditect plugin to handle modular dependency bundling if required.
  3. Build a custom jlink runtime with just your module and its dependencies:
    jlink --output modsim-runtime \
      --module-path /Users/johnallen/Downloads/javafx-jmods-15.0.1:/path/to/your/modular-jar \
      --add-modules org.crob.modsim
    
  4. Package with jpackage using this runtime—no more manual module lists needed!

Troubleshooting Step to Verify

If you still run into issues, check the installed app's runtime and launch script:

  1. Navigate to the app's directory: /Applications/ModSim.app/Contents
  2. Check if java.naming is present in the runtime:
    ./runtime/Contents/Home/bin/java --list-modules | grep java.naming
    
  3. Try launching the app directly from the command line to test flags:
    ./runtime/Contents/Home/bin/java --add-modules javafx.controls,javafx.fxml,java.naming -jar ./app/modsim-1.0-SNAPSHOT.jar
    
    If this works, the issue is with the auto-generated launch script—fix it by adding the --add-modules flag via jpackage's --java-options.

内容的提问来源于stack exchange,提问作者johnda98

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.29 05:38:25