Limit modules added by javapackager

I am trying to reduce the size of my application by limiting the modules that it includes. I have already done this for my runtime using jlink . However, when I run javapackager using the javapackager --add-modules and --limit-modules options with a comma separated list of the same small set of modules that I used for the runtime, it still insists on adding all the modules. It seems that he does not want to respect the option that I give him. How can I get a tool to restrict the modules that it adds to my application package?

 "Adding modules: [java.base, java.desktop, java.naming, java.sql, java.xml, java.logging, java.management, java.scripting, java.compiler, java.rmi, java.activation, jdk.charsets, jdk.xml.dom, java.datatransfer, jdk.httpserver, javafx.base, java.security.sasl, jdk.zipfs, jdk.crypto.ec, jdk.management.agent, java.sql.rowset, javafx.swing, jdk.jsobject, jdk.sctp, java.smartcardio, jdk.unsupported, jdk.scripting.nashorn, java.security.jgss, javafx.graphics, javafx.fxml, jdk.dynalink, javafx.media, jdk.accessibility, jdk.security.jgss, javafx.web, java.xml.crypto, jdk.jfr, jdk.packager.services, jdk.net, javafx.controls, java.prefs, jdk.naming.rmi, jdk.jdwp.agent, java.instrument, jdk.management, jdk.security.auth, java.management.rmi, jdk.naming.dns, jdk.localedata] to runtime image." outputDir = ... modulePath = [/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/jmods] addModules = [java.base, java.desktop, java.naming, java.sql, java.xml, java.logging, java.management, java.scripting, java.compiler, java.rmi, java.activation, jdk.charsets, jdk.xml.dom, java.datatransfer, jdk.httpserver, javafx.base, java.security.sasl, jdk.zipfs, jdk.crypto.ec, jdk.management.agent, java.sql.rowset, javafx.swing, jdk.jsobject, jdk.sctp, java.smartcardio, jdk.unsupported, jdk.scripting.nashorn, java.security.jgss, javafx.graphics, javafx.fxml, jdk.dynalink, javafx.media, jdk.accessibility, jdk.security.jgss, javafx.web, java.xml.crypto, jdk.jfr, jdk.packager.services, jdk.net, javafx.controls, java.prefs, jdk.naming.rmi, jdk.jdwp.agent, java.instrument, jdk.management, jdk.security.auth, java.management.rmi, jdk.naming.dns, jdk.localedata] limitModules = [java.base, java.desktop, java.naming, java.sql, java.xml, java.logging, java.management, java.scripting, java.compiler, java.rmi, java.activation] 

Here is the command I am running with replacing some things like username:

 /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin/javapackager -deploy -native image \ -name Commander -title Commander -vendor "username" \ -appclass com.username.commander.ui.AppWindow \ -srcdir /Users/username/Dropbox/coding/commander/Commander-java/packageJars \ -outdir /Users/username/Dropbox/coding/commander/Commander-java/target \ -outfile Commander \ -Bruntime=target/jre-9.0.1 -Bicon=src/main/resources/icons/commander.icns \ -BappVersion=1.0 \ -Bmac.CFBundleIdentifier=com.username.Commander \ -BmainJar=commander-0.0.1-SNAPSHOT-jar-with-dependencies.jar \ --add-modules java.base,java.desktop,java.naming,java.sql,java.xml,java.logging,java.management,java.scripting,java.compiler,java.rmi,java.activation \ --limit-modules java.base,java.desktop,java.naming,java.sql,java.xml,java.logging,java.management,java.scripting,java.compiler,java.rmi,java.activation \ -nosign -v 
+5
java java-9 java-module javapackager
source share
2 answers

So, it turns out that the reason why he did not perform my settings is that my jar application is not a Java 9 module. This is a simple old jar. In Java 9, javapackager uses jlink to generate a runtime and will not try to limit the number of modules because it cannot determine module dependencies. The -Bruntime option is for Java Web Start applications only. If you want javapackager not to use jlink , you should use it in JDK 8.

I can’t turn my application bank into a module because of the complexity associated with all the dependencies of a third party (you can see the details in this question ). And I can't use JDK 8 because I need some APIs added to the Desktop module in Java 9. So, I found a workaround to get finer runtime in the application using Java 9 javapackager :

  • Create a more subtle runtime using jlink , specifying only the modules you need using the --add-modules option. You can use the jdeps command to find out which modules all banks need in your application.
  • Create .app with the full version using javapackger as usual.
  • Open your generated .app file (macOS) or for Windows, use something that will allow you to edit the .exe or .msi installer (I don’t know how to do it myself).
  • On macOS, replace the contents of <myApp>.app/Contents/PlugIns/Java.runtime/Contents/Home with those used in your thinner runtime. Do something similar for Windows Installer.
+1
source share

Using the javapackager command line, you can use the deployment options --limit-modules and --add-modules , such as: -

 javapackager -deploy --add-modules java.base,java.desktop... --limit-modules java.base,java.desktop,java.naming... --module-path your.mods.dir -native -outdir OUTPUT_DIR -outfile APPLICATION_NAME -srcdir PACKAGE_SRC_DIR -srcfiles APPLICATION.jar -appclass MAIN_CLASS -name "YourApplication" -title "SelfContained" 

Or in normal mode, the ant deployment task will consist of the following: -

 <fx:runtime strip-native-commands="false"> <fx:add-modules value="java.base"/> <fx:add-modules value="java.desktop,java.naming..."/> <fx:limit-modules value="java.base"/> <fx:limit-modules value="java.desktop,java.naming..."/> <fx:module-path value="${java.home}/../images/jmods"/> <fx:module-path value="${build.dir/modules"/> </fx:runtime> 
+1
source share

All Articles