So my problem is openjfx and using it on Scala-sbt project. The actual problem is JAVAFX_HOME path.

First of all I have java version 10.0.2 installed on my computer and openjfx (which I take as JavaFX) is on ubuntu repositories based on java 8jre (openjdk-8-jre is required). So when I install it needs another version of java.

But still after installing openjfx my sbt build will not open a project and gives an error



Caused by: java.util.NoSuchElementException: key not found: JAVAFX_HOME

I take that this since java current version is 10 and javafx is on 8. However when I try to do

 update-alternatives --config java

and select version 8, java seems not to work on at all. The output of java --version says then:

Unrecognized option: --version

Error: Could not create the Java Virtual Machine.

Error: A fatal exception has occurred. Program will exit.

So, Is there a way to export only javafx to .bashrc similar to this:

export JAVA_HOME="$(jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));')"

to get JAVAFX_HOME path working or do I have to reinstall java to java 8 somehow to get javafx working correctly?

  • Welcome to Ask Ubuntu! possible duplicate of askubuntu.com/questions/609951/… – abu-ahmed al-khatiri Sep 25 '18 at 16:32
  • Thank you. This led to the right path while it was exactly correct. The error indeed was in etc/environment file. – Hjell Sep 25 '18 at 18:57
  • * was not exactly correct – Hjell Sep 25 '18 at 19:17

Ok so sbt had errors since the build file had references to the system environemnt [system.getenv("JAVA_HOME")) in java and in sbt it was scala.sys.env("JAVA_HOME") and similarly to JAVAFX_HOME]

It is common to use JAVA_HOME system variable so this is added in linux by adding the location of java installation to the /etc/environment file. Mine was JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64". Remember to not use CLASSPATH in the environment file since it hinder the running of java files.



Remember to reboot after setting new environment variables.

Also note that update-alternatives should be done both to java and javac. And the

java --version 

does not work since in java 8 it is just

java -version

Also in sbt you can use this line to to add

 unmanagedJars in Compile += Attributed.blank(
   file(System.getenv("JAVA_HOME") + "/jre/lib/jfxrt.jar"))

to set current jfxrt (javaFX) file wherever that is (modify accordingly)

  • It's better to use a file in /etc/profile.d rather than /etc/environment. It's a bit like the difference between using /etc/apt/sources.list.d and /etc/apt/sources.list. – Chai T. Rex Sep 25 '18 at 19:37
  • What exact file? There is few of them but none of the seem to suite the purpose. Or is just to create new file and the system automatically scans it? I also assume that export JAVA_HOME should be used? – Hjell Sep 25 '18 at 19:54
  • Create a new .sh file and make it executable and, when the system reboots, it'll pick it up like /etc/environment is picked up. For example, here's the file that oracle-java10-installer adds: /etc/profile.d/jdk.sh. – Chai T. Rex Sep 25 '18 at 20:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.