Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add compile time dependencies for Java 9+ #151

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

add compile time dependencies for Java 9+ #151

wants to merge 4 commits into from

Conversation

xzel23
Copy link
Contributor

@xzel23 xzel23 commented Jan 31, 2019

This adds the java.xml.bind dependency for Java 9+ and also JavaFX for JDK 11+. I can now compile FXLauncher under both JDK 8 and 11. The resulting jar should work as before on Java 8. I cannot test Java 9 and 10, but to actually run on Java 11, more tweaks are needed.

I tried to test this with the fxldemo project, and both jars (= compiled with JDK 8 vs JDK 11) work the same when run under JDK 8. I get an error "WARNING: Error during Update Manifest phase" when I replace the original fxlauncher.jar with the new SNAPSHOT version though. But I see the same error when replaing with the original SNAPSHOT version (not containing my changes), so this seems unrelated.

When running on JDK 11, I get this error:

Error: Could not find or load main class fxlauncher.Launcher
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

I will look into the issue with running under Java 11 later.

@edvin
Copy link
Owner

edvin commented Jan 31, 2019

Great start. I will wait with merging until it works with J11, OK?

@xzel23
Copy link
Contributor Author

xzel23 commented Jan 31, 2019

Ok, works now (still getting java.lang.IllegalArgumentException: Unable to retrieve embedded or remote manifest.).

On Java 11, using jaxb pulls in a lot of dependencies that are required on the runtime classpath. I think XML should either be required by JSON or the code rewritten to use org.w3c instead which is stiill part of the JDK.

That's bout what I can do for now. I think next problem will be the one remaining use of internal API. But I can only continue there once the "Unable to retrieve embedded or remote manifest" issue is solved.

More detail on what I did and how to run on Java 11 (did not try on Java 9 and 10 because I don't have them installed and both have already reached EOL):

  • problem 1 was that in Java 11 main() inside a class extending Application is not called. So I moved main() to a new class Main and updated the POM accordingly.

  • next ist that you have to have the dependencies on the classpath.

To run in Java 8:

java -jar ./fxlauncher.jar

To run in Java 11:

  • define JFX_PATH
  • make sure to have these on the classpath
    javax.activation-api-1.2.0.jar
    jaxb-api-2.3.0.jar
    jaxb-core-2.3.0.jar
    jaxb-impl-2.3.0.jar
    and run
    java --module-path=$JFX_PATH --add-modules=javafx.controls,javafx.web
    --class-path=./fxlauncher.jar:./jaxb-api-2.3.0.jar:./jaxb-impl-2.3.0.jar:./jaxb-core-2.3.0.jar:javax.activation-api-1.2.0.jar
    fxlauncher.Main

@xzel23
Copy link
Contributor Author

xzel23 commented Jan 31, 2019

OK, I found out why the manifest could not be loaded. I did not use the --app parameter. Now that I do, an NPE is thrown later on.

I think I learned enough about FxLauncher to fix the remaining problems. I will let you know when everything works and this is ready and working in both Java 8 and 11. Please wait with merging.

@xzel23
Copy link
Contributor Author

xzel23 commented Feb 1, 2019

After I have looked deeper into this, this is where we are now:

  • Compilation works under Java 8 and 11, 9 and 10 should also work but I have not tested these.
  • The resulting jar is compatible with Java 8 (successfullly tested with fxldemo application).
  • The jar also works on Java 11 (and should on 9 and 10) if you provide the correct flags (see below).
  • However fxldemo itself will throw an exception because the used version of controlsfx is not compatible with Java 9+. (Guys, why does everyone keep using private APIs through reflection?)
  • The classes pulled in to do the XML parsing (only necessary on Java 9+) weigh in at about 1.4 MB, so maybe this could be changed to something more lightweight (JSON?) in a later release.
  • It is not possible to remove the usage of private APIs because of the implementation of the JavaFX Launcher class. This should already have crashed with the original Pull request, but I cannot verify. This makes it necessary to add those ugly --add-open switches on Java 11+.

How to run fxldemo in Java 11 (change paths accordingly):

    java --module-path=/Users/axel/Development/libs/javafx-sdk-11.0.2/lib \
        --add-modules=javafx.controls,javafx.web,javafx.fxml,javafx.base \
        --add-opens=javafx.graphics/com.sun.javafx.application=ALL-UNNAMED
        --add-opens=javafx.base/com.sun.javafx.runtime=ALL-UNNAMED
        --class-path=./fxlauncher.jar:../../lib/jaxb-api-2.3.0.jar:../../lib/jaxb-api-2.3.0.jar:../../lib/jaxb-core-2.3.0.jar::../../lib/jaxb-impl-2.3.0.jar:../../lib/activation-1.1.1.jar fxlauncher.Launcher \
        --app=app.xml

@aarighi
Copy link

aarighi commented Dec 20, 2019

Hi! Thanks for the great work, but since this thread has not been updated in a while I need to ask: is anyone still working on this? Is this ever going to be merged in FXLauncher?

Thanks again (:

@edvin
Copy link
Owner

edvin commented Dec 20, 2019

I don't have time to work on this at the moment. Eventually I'll update it when I need to use JDK13+ myself, but in the mean time anyone is free to contribute :)

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

Successfully merging this pull request may close these issues.

3 participants