JAVAFX_HOME path on ubuntu

11,353

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.

/etc/environment:

...
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
JAVAFX_HOME="/usr/share/java/openjfx"  

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)

Share:
11,353

Related videos on Youtube

Hjell
Author by

Hjell

Updated on September 18, 2022

Comments

  • Hjell
    Hjell over 1 year

    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

    java.lang.ExceptionInInitializerError

    ...

    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?

    • abu-ahmed al-khatiri
      abu-ahmed al-khatiri over 5 years
      Welcome to Ask Ubuntu! possible duplicate of askubuntu.com/questions/609951/…
    • Hjell
      Hjell over 5 years
      Thank you. This led to the right path while it was exactly correct. The error indeed was in etc/environment file.
    • Hjell
      Hjell over 5 years
      * was not exactly correct
  • Chai T. Rex
    Chai T. Rex over 5 years
    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.
  • Hjell
    Hjell over 5 years
    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?
  • Chai T. Rex
    Chai T. Rex over 5 years
    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.
  • Marcel Waldvogel
    Marcel Waldvogel over 4 years
    You also do not need to reboot. Just sourcing the file is enough (". /etc/profile.d/javafx.sh", if it has been stored as "javafx.sh"). Please pay attention to the ".", this is the "source" command.