Skip to content
This repository has been archived by the owner on Oct 13, 2021. It is now read-only.

[WIP] Java11 migration #45

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open

[WIP] Java11 migration #45

wants to merge 36 commits into from

Conversation

geofjamg
Copy link
Member

No description provided.

@jonenst
Copy link
Contributor

jonenst commented Jan 28, 2019

Using the following patch, I get a jar that starts the GUI with java 11:

$ echo $JAVA_HOME
[...]/jdk-11.0.2/

$ mvn clean package -Pnative-package
[.. snip ..]
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] 
[INFO] Grid Study Environment ............................. SUCCESS [  1.138 s]
[INFO] GSE SPI ............................................ SUCCESS [  3.005 s]
[INFO] GSE utilities ...................................... SUCCESS [  1.669 s]
[INFO] GSE integration of AFS base extensions ............. SUCCESS [  0.913 s]
[INFO] GSE application .................................... SUCCESS [  0.997 s]
[INFO] GSE network explorer ............................... SUCCESS [  0.694 s]
[INFO] GSE network map .................................... SUCCESS [  0.683 s]
[INFO] GSE security analysis .............................. SUCCESS [  0.872 s]
[INFO] GSE demo ........................................... SUCCESS [  9.626 s]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS

$ $JAVA_HOME/bin/java -jar  gse-demo/target/shade/powsybl-gse-demo.jar

Got the implementation from https://openjfx.io/openjfx-docs/#modular (see the Non-Modular project section) and disabled the jar signature check with https://stackoverflow.com/a/6743609

I noticed it doesn't do a splash screen anymore.

Is this a good way forward or do we need something else ?

$ git diff
diff --git a/gse-demo/pom.xml b/gse-demo/pom.xml
index c94249e..9ba034e 100644
--- a/gse-demo/pom.xml
+++ b/gse-demo/pom.xml
@@ -57,35 +57,35 @@
                         </executions>
                     </plugin>
                     <plugin>
-                        <groupId>com.zenjava</groupId>
-                        <artifactId>javafx-maven-plugin</artifactId>
-                        <version>${maven.javafx.version}</version>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-shade-plugin</artifactId>
+                        <version>${maven.shade.version}</version>
                         <configuration>
-                            <vendor>PowSyBl</vendor>
-                            <appName>gse</appName>
-                            <nativeReleaseVersion>${project.version}</nativeReleaseVersion>
-                            <mainClass>com.powsybl.gse.demo.GseDemo</mainClass>
-                            <skipJNLP>true</skipJNLP>
-                            <jvmProperties>
-                                <app.root>$APPDIR</app.root>
-                                <powsybl.config.dirs>${user_home}/.powsybl:${app.root}/app</powsybl.config.dirs>
-                                <javafx.preloader>com.powsybl.gse.app.GsePreloader</javafx.preloader>
-                            </jvmProperties>
+                            <shadedArtifactAttached>true</shadedArtifactAttached>
+                            <shadedClassifierName>project-classifier</shadedClassifierName>
+                            <outputFile>target/shade/${project.artifactId}.jar</outputFile>
+                            <filters>
+                                <filter>
+                                    <artifact>*:*</artifact>
+                                    <excludes>
+                                        <exclude>META-INF/*.SF</exclude>
+                                        <exclude>META-INF/*.DSA</exclude>
+                                        <exclude>META-INF/*.RSA</exclude>
+                                    </excludes>
+                                </filter>
+                            </filters>
+                            <transformers>
+                                <transformer implementation=
+                                                     "org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                                    <mainClass>com.powsybl.gse.demo.GseDemo</mainClass>
+                                </transformer>
+                            </transformers>
                         </configuration>
                         <executions>
                             <execution>
-                                <!-- required before build-native -->
-                                <id>create-jfxjar</id>
-                                <phase>package</phase>
-                                <goals>
-                                    <goal>build-jar</goal>
-                                </goals>
-                            </execution>
-                            <execution>
-                                <id>create-native</id>
                                 <phase>package</phase>
                                 <goals>
-                                    <goal>build-native</goal>
+                                    <goal>shade</goal>
                                 </goals>
                             </execution>
                         </executions>
diff --git a/pom.xml b/pom.xml
index 7405fd0..03a6fb1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -71,7 +71,7 @@
         <maven.compiler.version>3.8.0</maven.compiler.version>
         <maven.deploy.version>2.8.2</maven.deploy.version>
         <maven.enforcer.version>3.0.0-M2</maven.enforcer.version>
-        <maven.javafx.version>8.8.3</maven.javafx.version>
+        <maven.shade.version>3.2.1</maven.shade.version>
         <maven.gpg.version>1.6</maven.gpg.version>
         <maven.install.version>2.5.2</maven.install.version>
         <maven.jar.version>3.1.0</maven.jar.version>

@jonenst
Copy link
Contributor

jonenst commented Jan 28, 2019

The splash screen is displayed when using the following command line

$ JAVA_HOME/bin/java -jar -Djavafx.preloader=com.powsybl.gse.app.GsePreloader  gse-demo/target/shade/powsybl-gse-demo.jar

@jonenst
Copy link
Contributor

jonenst commented Jan 28, 2019

I ran jdeps on the shaded jar according to https://medium.com/azulsystems/using-jlink-to-build-java-runtimes-for-non-modular-applications-9568c5e70ef4
(I'm not sure we need the javafx sdk and modules because of the uberjar..)

$ $JAVA_HOME/bin/jdeps --module-path /path/to/javafx-sdk-11.0.2/lib --add-modules=javafx.controls --list-deps gse-demo/target/shade/powsybl-gse-demo.jar 

   JDK removed internal API/com.sun.javafx.css.converters
   JDK removed internal API/com.sun.javafx.scene.control.behavior
   JDK removed internal API/com.sun.javafx.scene.control.skin
   JDK removed internal API/com.sun.media.jfxmediaimpl.platform.ios
   JDK removed internal API/com.sun.media.jfxmediaimpl.platform.osx
   JDK removed internal API/sun.misc
   JDK removed internal API/sun.reflect
   java.base/sun.nio.ch
   java.compiler
   java.datatransfer
   java.desktop/java.awt.dnd.peer
   java.desktop/sun.awt
   java.desktop/sun.awt.dnd
   java.desktop/sun.swing
   java.logging
   java.management
   java.management.rmi
   java.naming
   java.prefs
   java.rmi
   java.scripting
   java.security.jgss
   java.sql
   java.xml/com.sun.org.apache.xml.internal.utils
   java.xml/com.sun.org.apache.xpath.internal
   java.xml/com.sun.org.apache.xpath.internal.objects
   java.xml.crypto
   jdk.javadoc
   jdk.jsobject
   jdk.unsupported
   jdk.unsupported.desktop

Stripping the modules subpackages, I created a runtime:

$ $JAVA_HOME/bin/jlink --add-modules java.base,java.compiler,java.datatransfer,java.desktop,java.logging,java.management,java.management.rmi,java.naming,java.prefs,java.rmi,java.scripting,java.security.jgss,java.sql,java.xml,java.xml.crypto,jdk.javadoc,jdk.jsobject,jdk.unsupported,jdk.unsupported.desktop   --output java-runtime

It's 105Mb.

I also created a runtime with jlink through trial and error just by adding the modules of the missing classes at startup which gave:

$ $JAVA_HOME/bin/jlink --add-modules java.base,java.logging,java.xml,java.naming,java.scripting,java.desktop,jdk.unsupported,java.management --output java-runtime

It's 85Mb

In both cases I ran the app by copying the uberjar to java-runtime/lib and launching it with java-runtime/bin/java -jar java-runtime/lib/powsybl-gse-demo.jar
the uberjar is 84 Mb.

Jon Harper added 2 commits January 31, 2019 16:07
Tested on linux only.
This shouldn't work on windows because the docs say
"
For Windows, you have to unzip the bundle in the same directory as the JDK,
as the packager wrapper expect to find the java binary at the same level.
"

Maybe it will work in the future with a new release from
http://download2.gluonhq.com/jpackager/11/jdk.packager-windows.zip

In the meantime, users should be able to move the downloaded jpackager
to their jdk themselves and invoke maven with the correct path to the packager
with something like this (untested):
mvn -Djpackager.path=C:\\Path\\To\\JDK\\bin\\jpackager
@jonenst
Copy link
Contributor

jonenst commented Feb 1, 2019

I implemented the native package with the infos from https://mail.openjdk.java.net/pipermail/openjfx-dev/2018-September/022500.html and https://github.com/skymatic/javafx11-test/ and tested it on my machine (fedora 27).
The output image has the same structure as the image I was getting from com.zenjava:javafx-maven-plugin on java8
The cfg file also looks similar.

Jon Harper added 10 commits February 5, 2019 15:32
- The bug where we have to list the jars manually has been fixed
- We need to create a jdk11 runtime with jlink and pass it with --runtime to jpackage
- It should work on windows without having to provide the path manually
…build failures without mvn clean

This does not work when running mvn clean package because the profile is decided at the start..
…trying to detect it

The previous approach would fail for `mvn clean package` because the profile is activated
at the start of maven.
@jonenst
Copy link
Contributor

jonenst commented Feb 5, 2019

I have reimplemented this using https://jdk.java.net/jpackage/ . It's java13 early access jpackage.
I tested, it works on linux (fedora 27) and windows (windows 2012 R2).

I used the current JAVA_HOME (e.g. java11) jlink to create a runtime image that is fed to jpackage, so the resulting native app has nothing to do with java13.

The build also downloads jpackage (and the whole jdk, ~200Mbytes) but this is cached in M2_REPOSITORY/.cache by the download-maven-plugin.

Note: download-maven-plugin 1.4.1 doesn't use the http configuration from settings.xml for https downloads, so pay attention to duplicate your proxy configuration in settings.xml if you have one.

Using java13 early access jpackage was suggested here https://mail.openjdk.java.net/pipermail/openjfx-dev/2019-January/023055.html and here https://mail.openjdk.java.net/pipermail/openjfx-dev/2018-December/023003.html where the original provider for the backported jpackager said :
"However, I highly recommend testing the early access version of jpackage.
That is the way forward for the packager."

I couldn't get it to work though, jpackager.exe --version-swap [..]
was not doing anything on windows 2012 R2 (it is using
BeginUpdateResource, UpdateResource and EndUpdateResource
ms functions). But the config file does contain the following info in gse.properties:

Comments=
CompanyName=PowSyBl
FileDescription=gse
FileVersion=1.4.0-SNAPSHOT
InternalName=gse.exe
LegalCopyright=Copyright (C) 2019
LegalTrademarks=
OriginalFilename=gse.exe
PrivateBuild=
ProductName=gse
ProductVersion=1.4.0-SNAPSHOT
SpecialBuild=

But the exe file has:

D:\Users\harperjon> get-command "D:\Users\harperjon\Downloads\all\powsybl-gse\gse-demo\target\native\gse\gse.exe" | format-list
Name            : gse.exe
CommandType     : Application
Definition      : D:\Users\harperjon\Downloads\all\powsybl-gse\gse-demo\target\native\gse\gse.exe
Extension       : .exe
Path            : D:\Users\harperjon\Downloads\all\powsybl-gse\gse-demo\target\native\gse\gse.exe
FileVersionInfo : File:             D:\Users\harperjon\Downloads\all\powsybl-gse\gse-demo\target\native\gse\gse.exe
                  InternalName:     jpackageapplauncher
                  OriginalFilename: jpackageapplauncher.exe
                  FileVersion:      13
                  FileDescription:  OpenJDK Platform binary
                  Product:          OpenJDK Platform 13
                  ProductVersion:   13
                  Debug:            False
                  Patched:          False
                  PreRelease:       False
                  PrivateBuild:     False
                  SpecialBuild:     False
                  Language:         Langue neutre

The previous java8 implementation on windows 2012 R2 didn't work either:

D:\Users\harperjon> get-command "D:\Users\harperjon\Downloads\all8\powsybl-gse\gse-demo\target\jfx\native\gse\gse.exe" | format-list
Name            : gse.exe
CommandType     : Application
Definition      : D:\Users\harperjon\Downloads\all8\powsybl-gse\gse-demo\target\jfx\native\gse\gse.exe
Extension       : .exe
Path            : D:\Users\harperjon\Downloads\all8\powsybl-gse\gse-demo\target\jfx\native\gse\gse.exe
FileVersionInfo : File:
                  D:\Users\harperjon\Downloads\all8\powsybl-gse\gse-demo\target\jfx\native\gse\gse.exe
                  InternalName:
                  OriginalFilename:
                  FileVersion:
                  FileDescription:
                  Product:
                  ProductVersion:
                  Debug:            False
                  Patched:          False
                  PreRelease:       False
                  PrivateBuild:     False
                  SpecialBuild:     False
                  Language:
Jon Harper added 2 commits February 6, 2019 16:34
I tested that it works on windows.
On linux, jpackage doesn't do anything with the icon for create-image.
Untested on mac.
@jonenst
Copy link
Contributor

jonenst commented Mar 5, 2019

Apparently they have fixed the problem of not setting the versioninfo of the windows exe, but we need to wait jpackage EA4 to test it. https://mail.openjdk.java.net/pipermail/core-libs-dev/2019-February/058704.html

@jonenst
Copy link
Contributor

jonenst commented Mar 22, 2019

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants