JavaFX only run with JDK - java

My JavaFX Desktop program only run with JDK 1.8 installed, doesnt run with JRE 1.8.
Any JavaFX Application should run with JRE?
If NO, How can I find why JDK is needed?

This is because JavaFX runtime is not packaged into some distributions of JRE. As far as I know JavaFX will be in all distributions only when JDK 9 is released. Till then, it is safer to install JDK instead of JRE, or you can include jfxrt.jar when you export your project into JAR file.

Per Oracle's documentation, the JavaFX SDK and Runtime (jfxrt.jar) are included in the Java JDK, beginning with Java SE 7 Update 2. As long as the application was compiled with this version or later, it should run JavaFX.
Also per their site, the JavaFX APIs are fully integrated with the Java SE Runtime Environment (JRE) and the Java Development Kit (JDK).
The specific location where you should find jfxrt.jar in both the JDK and JRE is:
For Java 7, under jre\lib
For Java 8, under jre\lib\ext
Additional info can be found at Oracle's various JavaFX resources such as here and here - though the latter was created for JavaFX 2, so may not be entirely compatible with the latest version of JavaFX.

Related

How to use JFX/OpenFX with OpenJDK 8

Is there any javafx/OpenJFX dependency which can be used directly in the pom file so that it works with OpenJDK 8? Or any workaround (without installing anything) which works with OpenJDK 8?
I have gone through a lot of similar questions on SO, but the solution to use JFX/OpenFX with OpenJDK 8 is either to install the openjfx package in Ubuntu OR use Oracle JDK 8. Unfortunately I cannot do both. I am using OpenJDK 8 and need to use javafx/OpenJFX within my swing application. The OpenJDK does not contain jfxrt.jar in its ext folder (as in case of Oracle JDK 8), and the versions of OpenJFX start from Java 9/10. And on trying to compile I get
class file has wrong version 54.0, should be 52.0 which is expected as it is build with Java 10
Any leads would be really helpful. Thanks!
I have already gone through the below links
Why is JavaFX is not included in OpenJDK 8 on Ubuntu Wily (15.10)?
"class file has wrong version 54.0, should be 52.0" while trying to build JavaFX application
"class file has wrong version 54.0, should be 52.0" while compiling javaFX project
How to find out JavaFX version
Is there any javafx/OpenJFX dependency which can be used directly in the pom file so that it works with OpenJDK 8?
AFAIK, no. There are org.openjfx artifacts for OpenJFX 11 onwards, but they won't work with Java 8. (The class file version will be wrong.)
Or any workaround (without installing anything) which works with OpenJDK 8?
I think you will need to build your own copy of OpenJFX from source, and (touch wood) "package it" with your application1.
(The following is purely based on reading the OpenJFX build instructions. I have not tried this out.)
So if you want to build a stand-alone OpenJFX 8 for use with OpenJDK 8, then you should try the following build instructions on the OpenJFX wiki:
Building OpenJFX 8u
The result of the build is (apparently) a ZIP file that is designed to be "overlayed" onto a JRE installation.
You may be able to repackage that into JARs and native libraries that you can include in your application.
For OpenJFX 9 and later, the build instructions are here:
Building OpenJFX
Apparently, for N >= 9, OpenJFX version N is supposed to be supported for OpenJDK N and OpenJDK N - 1. So if that is accurate, you should be able to build OpenJFX 9 for OpenJDK 8. On the other hand, the build instructions talk about generating modules, and module support is only available in Java 9 and later. However it is still worth a try (IMO).
1 - Options include 1) creating a custom Debian package(s) (or RPMs) ... analogous to the existing Ubuntu packages, 2) incorporating the relevant classes and native libraries into your application JAR, or 3) adding them to your applications classpath and library load path. You may need to experiment.
Why don't you just use, e.g., https://bell-sw.com/pages/downloads/#/java-8-lts and download the full Java version (not standard). It should already contain JavaFX and is one of the many OpenJDK 8 versions floating arround.

Use OpenJML in Eclipse project that uses JDK different from OpenJDK 1.8

OpenJML is available as Eclipse Plugin (install site http://jmlspecs.sourceforge.net/openjml-updatesite ) and it seems to get installed OK in Eclipse Photon.
But docs say it shall run only on OpenJDK 1.8 and it cannot be any other JDK (say, Oracle JDK). Also it cannot be (OpenJDK) version different than 1.8 (say 1.9).
My Projects in Eclipse all use (Oracle) JDK, besides soon we plan upgrading from JDK 1.8 to 1.9.
Can I setup OpenJML so that it uses its wanted OpenJDK 1.8, while my project uses whatever it needs?
OpenJML builds upon the OpenJDK 1.8 Compiler internally.
Of course, you can run OpenJML (with JRE 1.8) and the Java 9 compiler against the same Java sources (outside of eclipse; in a build tool), but OpenJML won't understand new language features (Modules, etc.) or API changes. So you need to stick with Java 1.8 API and features, hence besides of JVM improvements, you don't get any benefit of using Java 9.

is it mandatory to having same version of jdk and jre?

I am having java JDK version 11 and JRE version 8, it will occur any problem in feature or not? is it mandatory to have same jdk version and jre version?
If your code is using features of Java 11, you will need the JRE 11 to run it. But as long as you develop your code against JRE 8, it doesn't matter which JDK you use to develop and compile with.
You can set your project in your IDE to a compatibility level of JRE 8 (like here). This prevents any usage of features newer than Java 8.
Example: Develop with JDK 11 but only use features from Java 8 -> code will run in JRE 8. See the older versions as subsets of the newer ones.
If you compile code targeting Java 8, and don't use any newer APIs, you can run it on either.
If you build for Java 11, but try to run on Java 8 it won't work.
The simplest thing to do is to use the JVM the software was built on (or a newer version)
No. Because you never use both of them at the same time.
JRE is Subset of JDK.
JDK includes the Java Runtime Environment (JRE), an interpreter/loader (java), a compiler (javac), an archiver (jar), a documentation generator (javadoc) and other tools needed in Java development.
If you Open your JDK folder (C:\Program Files\Java\jdk1.8.0_152) , you can find JRE there.
Coming to your Question; No it is not necessary to have both JDK and JRE of same version as we don't use both at the same time.

Running javafx application on java 1.8

I have noticed that in jdk folder javafx-src.zip is separate from src.zip.
Is it included in the jre? Will it run in all java 8 VMs?
I have noticed that in jdk folder javafx-src.zip is separate from src.zip. Is it included in the jre?
No. The JRE only needs to include binary runtime code, it does not need to include source code. Only the JDK includes source code. So, the JRE includes neither src.zip, nor javafx-src.zip.
Will it run in all java 8 VMs?
VMs yes, JREs no. For example if you have an Oracle server JRE or an OpenJDK JRE distribution which does not include JavaFX client runtime code, then your JavaFX application will not run on those environments. All full (non-server only) distributions of Oracle Java SE 8 (except Solaris) include a compatible runtime for JavaFX 8, so you can execute a JavaFX 8 compatible application directly on the Oracle Java SE 8 JRE without any additional installations.
To ensure that your target machine has a compatible JRE installed for executing your application, you may wish to package your application as a self-contained application.
Yes as of JDK 7u6 JavaFX is included with the standard JDK and JRE bundles.
Source: http://www.oracle.com/technetwork/java/javafx/downloads/index.html

which java version need to be uninstall

I already researched on how to install Eclipse Luna. One of the things to consider before installing Eclipse is to choose the JDK (planning to use JDK 8). It said that it is recommend that if I have an older version of Java, I need to uninstall it. But here's the problem: I don't know which I should uninstall. Here is the list of installed versions in my control panel (Windows 7 64bit):
Java 7
Java(TM) 6 Update 45
Java(TM) SE development kit 6 (i think this one but what's with (TM)?)
It is strongly recommended to specify what JVM (preferably a JDK) Eclipse should run in, via the eclipse.ini file. That way you can have any number of JDKs and/or JREs without problem. In fact, Eclipse also allows you to have multiple Java versions on your machine and each project in Eclipse can dictate exactly which one it uses. You can easily mix-and-match projects that use different Java versions, and they're all independent of the JVM that Eclipse itself is running in.
run java -version at the command line to see which one is in your PATH. This is the one that will run the Eclipse workspace.
Unless you have clear requirements to use older Java versions, I would recommend to uninstall all of them. And just have the latest JRE or better JDK installed.
In my case, I have a JRE to run the Eclipse workspace that is maintained by the Admin people and a private JDK (to provide additional tools, such as javadoc) to support the software development. You can have several Java versions installed (without having them in the PATH environment listed). You can point to them in the workspace settings or in specific Eclipse projects, e.g., to use a Java 6 for a certain project.
I think Eclipse Luna needs Java 7.
A Java 7 JRE/JDK is required for most of the Luna package downloads based on Eclipse 4.4.
In my opinion you can uninstall Java(TM) 6 Update 45 & Java(TM) SE development kit 6

Categories