Unable to create javafx application under java 9 focusing on java 8

I am trying to create a GUI application created using JavaFX and targeting java 8 with the flag of the new version of java 9.

compilation

import javafx.application.Application; public class Testing { public static void main(String... args) { } } 

when setting up java 9 with

 javac Testing.java 

works fine (also when using --release 9 ), but when I add the release flag

 javac --release 8 Testing.java 

cannot compile, no errors exist

 Testing.java:1:error: package javafx.application does not exist 

No problem compiling in javk javac. I tried using the --add-modules flag to add jfx modules, but this flag is not allowed when setting release to 8.

Is there any way to make this work under java 9? It doesn't seem like he thinks jfx packages are included in java 8, but they are (at least in oracle release).

I am using version java 9 for release on Windows and building the same application without problems in the latest version of java 8.


I tried adding jfxrt.jar from my java 8 installation (not rt.jar ) to the class path when compiling with the --release 8 flag and it works.

I understand that one of the goals of the release flag was to remove the need to have several versions of the JDK installed (or at least their rt.jar files). I'm not sure if the intention was only to remove the compilation need for this single file, or if the goal was to remove the compilation need for any packed JDK files (and jfxrt.jar included in JDK8 [at least in the Oracle version], which does not require any either special flags or modifications to the path to it).

Not sure of the intention, it somehow seems wrong that something will compile fine under java 8, but to compile (and only compilation is not required) compilation (and only compilation fails) under java 9 targeting to java 8 (but not when targeting java 9), and therefore several JDKs are required. For those who are more familiar with the intended implementation of the release flag, should this work this way?

+5
source share
1 answer

The behavior seems strange, although in terms of how the --release flag internally --release necessary jdk inner classes. But due to the fact that * rt.jars is removed in JDK9 and that javafx.application is part of jfxrt.jar , this may be the likely reason that the same will complain about the missing package.


The compilation section is from the migration guide , although it explains in detail that the --release N flag is conceptually a macro for:

 -source N -target N -bootclasspath $PATH_TO_rt.jar_FOR_RELEASE_N 

Therefore, this should work if you are sure to try something like this:

 javac -source 8 -target 8 -bootclasspath some/path/to/jdk1.8.0_65.jdk/Contents/Home/jre/lib/rt.jar Testing.java 

The simple solution when replacing the above, of course, is to add the jfxrt.jar file to the classpath and then compile using the --release 8 flag.


Note : still leaves me puzzled why --release won't find previous versions of rt.jar ? β€œPerhaps you want to check for such errors.”

From the comments : - JavaFX is considered to be an enabled extension in Java 8, so this is not allowed when targeting version 8. Only classes that would be in the rt.jar file are allowed.

+5
source

Source: https://habr.com/ru/post/1272352/


All Articles