0

OK, here's my problem. I wrote some code using Java 9 which compiles and runs perfectly when using JRE 10.0.2. This code has a GUI written in JavaFX that allows users to select directories to be watched using a variation of this code: https://docs.oracle.com/javase/tutorial/essential/io/notification.html .

I planned on using this code in a research project where I run this code on some other people's machines - who may or may not have admin privileges to install the JRE on their own. This means that I should use a supported version of the JRE so that IT doesn't give me grief - which basically means Java 8 or Java 11.

Problem: My code doesn't work with either version. This leaves me with the following scenarios: (1) refactoring my code to be compatible with Java 8 or (2) refactoring my code to be compatible with Java 11.

I have made a cursory attempt to switch my language from 9 to 8, but I am getting the following errors:

java: package javafx.animation does not exist
java: package javafx.application does not exist
java: package javafx.concurrent does not exist
java: package javafx.geometry does not exist
(+ a few more javafx packages)
Java: package com.sun.nio.file does not exist

I have tried searching via Google and Stack Overflow for the solution to this problem but I have not found anything.

I have also started to look into using Java 11, following this post: Intellij can't recognize javafx 11 with OpenJDK 11 and I have tried every possible solution in the thread, but I'm getting the following error message:

JavaFX runtime components are missing, and are required to run this application

How can I solve these issues?

Thanks!

Update: I downloaded JavaFX from https://openjfx.io/ and added that to my library, which solved the issue with all the JavaFX imports. The com.sun.nio.file package is being much more tricky to nail down.

  • My gut reaction is: Java 11 should be backward compatible with **all** code that runs on Java 9. The fact that yours isn't working makes me think the problem lies with something other than what version of Java you're using. E.g. perhaps your Java 11 doesn't work at all. Can you provide us with the entire class that works in 9? If you're not at liberty to show us the class, I would try making a small, separate project in Java 11 to verify that your installation / IDE is not the problem here. If that project doesn't work either, you'll have a minimal verifiable example for your next question :) – MyStackRunnethOver Oct 25 '18 at 17:25
  • Java 11 is not backward compatible with my code because they separated JavaFX from everything else (https://www.infoworld.com/article/3305073/java/removed-from-jdk-11-javafx-11-arrives-as-a-standalone-module.html). The entire class that works in 9 is massive, but I will do what you suggest to verify that my installation/IDE is working. Thanks! –  Oct 25 '18 at 17:29
  • Update: system.out hello world works fine with my installation of Java 11, this javafx code for hello world works for Java 10 but not Java 11 https://docs.oracle.com/javafx/2/get_started/hello_world.htm. –  Oct 25 '18 at 17:45
  • Looks to me like your dependencies are unavailable. `com.sun.nio.file` seems to reference an external library and javafx is an external library as well starting with java 11. No idea why you cannot compile your code with java 8, though. Some classes were moved from the `com.sun` packages to the `public` API though, which could result in issues... – fabian Oct 25 '18 at 18:43

1 Answers1

-1

This is hard to answer without more information about your code.

I think the reason for your problem is described here: "If you try to build a JavaFX application under JDK 9 while targeting Java 8, any attempt to resolve any JavaFX type will fail and compilation will abort." The reason for this is that JavaFX is included in JDK 9, but not in the JDK 8. If this is your problem, you need to include the JavaFX jar file in your build path.

AnnaME
  • 24
  • 4