I have some trouble with JavaFX. I wanted to start creating apps, desktop or mobile, at least something. So I found out I could use the JavaFX library for it. But as far as I understood, it was excluded from JDK 9. I'm actually using OpenJDK 11 on Ubuntu 18 (though Eclipse writes I have the JavaSE 10 environment, that is where I'm also a bit confused) and I installed OpenJFX using sudo apt install openjfx and I can't make Eclipse work with JavaFX.
I'm not sure if there's any sense not to use JDK 8 with the included JavaFX, but anyway, how can I use JavaFX in such conditions in Eclipse?
There are multiple points in your post which needs clarification. I will try to answer them in different bullet points:
But as far as I understood, it(JavaFX) was excluded from JDK 9.
JavaFX will be decoupled from Oracle JDK starting JDK 11. I stress on Oracle JDK because JavaFX was never a part of OpenJDK. Not even in OpenJDK 8.
I'm actually using OpenJDK 11 on Ubuntu 18 (Though eclipse writes I have JavaSE 10 environment, that is where I'm also a bit confused)
For Java 11 support in Eclipse, you need to install
Java 11 Support for Eclipse Photon plugin.
Here are a few Examples on how to run Java 11 applications in Eclipse
I installed openjfx using sudo apt install openjfx and I can't make eclipse work with JavaFX.
I'm not sure if there's any sense not to use JDK 8 with included JavaFX, but anyway, how can I use JavaFX in such conditions in eclipse?
Since OpenJDK 11 or Oracle JDK 11 will not come bundled with JavaFX, your best bet is to either download the JavaFX SDK from here or here and load them in your IDE.
If you are used to build tools, you can directly use the JavaFX runtime jars which are available in Maven Central.
For a tutorial on how to run JavaFX 11 on OpenJDK 11, you can follow:
Getting Started with JavaFX 11
JavaFX on JDK 11
JavaFX 11 and Eclipse
At the time of writing this post, you need Eclipse 4.9M3 to work with JavaFX 11.
Once you have eclipse, JDK 11 and JavaFX 11 SDK, you can either opt to create:
Module based project
Non-module based project (No module-info.java required)
Module based Project
Create a Java project and add JavaFX jars from the Java FX 11 SDK to the module path of the project.
Create a module.info and declare its dependency of javafx.controls module. javafx11 is the name of the package which contains your Java file.
module javafx11 {
requires javafx.controls;
exports javafx11;
}
Run the program \o/
Non-module based Project
Create a Java project and add JavaFX jars from the Java FX 11 SDK to either the module-path or classpath of the project.
Add the following JVM args to the run configuration of the project:
--module-path=path-to-javafx-skd/lib --add-modules=javafx.controls
Run the program \o/
tl;dr
To most easily get started with JavaFX, use the Oracle-branded release of Java 8 where JavaFX 8 is bundled and easily available.
For technical details, see Using JavaFX in JRE 8. Look to the Linked and Related sections of the web page for many related postings.
Java Modularization
The Java platform is in the process of a sweeping reformulation, known as modularization.
Previously, Java SE (standard edition) was one big monolith of software, ever-growing with more and more being added. No single app ever uses all of it.
A decision was taken to break Java SE into many separate chunks to be defined formally as “modules”. One major benefit is that an app may be bundled with a Java SE runtime composed of only the modules actually needed, with unused modules omitted. See the jlink tool.
As a byproduct of this modularization, some older and less-popular parts such as CORBA are being dropped, to no longer be carried as a standard part of Java (though offered for other parties to pick up if they so decide). Similarly, some Java EE related modules will be removed from Java SE and turned over to the Jakarta EE project, logically a more appropriate home. See JEP 320: Remove the Java EE and CORBA Modules.
The process of modularization and reorganization is a years-long ongoing effort. Much was done in Java 9 and Java 10. Some of the final steps are being done in Java 11.
One of these steps being taken in Java 11 is to cease bundling JavaFX with Java SE. See:
The Future work section of the JavaFX Wikipedia page
The 2018-03 Oracle blog post, The Future of JavaFX and Other Java Client Roadmap Updates
The 2018-03 Oracle white paper, Java Client Roadmap Update
The curse, May you live in interesting times
So getting started with JavaFX development right now will be easiest if done with Java 8. The JavaFX libraries are bundled in with Java 8. And you need not learn about modularization, nor need to wrestle your IDE (such as Eclipse) and project settings to recognize modules. If you do not have a pressing need to use the very last versions of Java or JavaFX, stick with 8 until the modularization process and tools gets smoothed out, likely next year 2019.
If you insist on using Java 11, you need to learn about:
Java modularization in general, including the module-info.java file.
Updating your IDE (Eclipse, etc.) and other tools to later versions supporting both modularization and Java 11.
Configuring modules in your build tools, such as Maven or Gradle
Configuring modules in your IDE, such as Eclipse
Downloading JavaFX modules, or using a dependency manager such as Maven to do so
Those points are too much to cover here, and have been covered in many other Questions on Stack Overflow. Besides, Java 11 has not yet been formally released.
Perhaps this article will help, How to Create a Project With JavaFX on JDK 11.
To learn much more about Java modularization, read the blog and the book, The Java Module System, by Nicolai Parlog.
I've had to struggle through this on about 20 computers now, so I made the following checklist:
[ ] download javafx11 from javafx11's website, put on desktop
[ ] create a MODULE based project
[ ] right click project, go to BUILD PATH
[ ] add the downloaded javafx.base/control/graphics as external jar files
[ ] put the files in a package (eg: my_big_package)
[ ] put the following in the module.java file:
module javafx11 {
requires javafx.controls;
exports my_big_package;
}
[ ] eat a donut from the break room
If you're not married to Eclipse and/or just trying to learn (or are a student with an unhelpful professor/TAs), BlueJ currently has JavaFX already built into it and ready to go, so no extra setup or download is necessary. Neat!
I've read that in Java 8, derby DB embedded driver in bundled(included). Is that true and if so how to refer to it in eclipse?
According to the technical notes (http://docs.oracle.com/javadb/index_jdk8.html) Java DB (Apache Derby) is only bundled (included) with the Java Development Kit (JDK 7 and JDK 8).
It does not come bundled (included) with the Java Standard Edition Java Runtime installations.
If you have a JDK installed, one way to access it from Eclipse is to add the /db/lib/derby.jar file into a user-defined library, and add that library to the build path of your project(s). This is the easiest, but highly discouraged as it will be hard to resolve these types of dependencies when the application needs to be launched outside of Eclipse.
Once you are comfortable with JavaDB, I would recommend that you use Maven/Gradle to manage building and deploying, as well as using Apache Derby.
We are planning to upgrade our J2EE application, I worked with a lot of jars before and I know that the version mismatch can be a hard problem to debug. We have all the jars(internal to company and built by some other team so cannot recompile with latest version ) compiled using 1.6 jdk and we are bumping up our application version to 1.7, but we are planning to use 1.6 version jars in our app. Does this work well? If not what should I do to make it compatible?
I'm sure that it will work well but, need some expert opinion on this.
Thank yo
As you can see on Oracle's homepage regarding compatibility of Java 1.7 it should be compatibale except for the following things
Binary Compatibility
Java SE 7 is binary-compatible with Java SE 6 except for the
incompatibilities listed below. Except for the noted incompatibilities,
class files built with the Java SE 6 compiler will run correctly in Java SE 7.
Quote from oracle
I installed JAVA SE JDK and then installed JAVA EE SDK java_ee_sdk-6u4-jdk7-windows-x64.exe
because the latter one requires a jre. But then I found that the java ee sdk is merely nothing new than java se but a combination of java se jdk+ glassfish platform. I do not know if I am right because I cannot find those "java ee" classes in it. (And the .jar files in jre/lib are the same) It is strange. Lets say JavaMail package, I cannot find it in my java ee jre but it is said this package is included in Java ee platform.
What I expected is the new apis and "java ee" source code which I could not find either. I really would like to know how to get a jdk which includes all the apis descripted at
http://docs.oracle.com/javaee/6/api/
Can some one tell me if I am right about this issue (JAVA EE SDK does not contain JAVA EE API)? If I am right, do I need to get each jar lib from the internet when I use it? Then what is the different between java se + external lib and java ee? Or Did I make any mistake when I installed?
Thank you guys!
According to java ee 5 api ExpressionFactory provides a method #newInstance.
I'm using the official javaee-api available in maven: Java EE 5 APIs now in a Maven repository...
But this jar does not provide this method. So I get compiler errors.
How can I get a compilable version without using javaee implementations like e.g. glassfish, openejb?
The official Java EE 6.0 jar provided by maven (java.dev.net) contains this method.
According to java ee 5 api ExpressionFactory provides a method #newInstance.
Well, javadoc is not a proof and, actually, this is very likely an error in the Java EE 5 javadoc. The two newInstance() factory methods have been added in the Maintenance Review 1 of the JSR-245 (to make EL standalone and take it out of JSP 2.1, have a look at the JSR-245 MR1 Change Log for the details) but that review has never been released.
So it's not surprising that you don't find this method in the java-ee bundle available in the java.net repo.
But this jar does not provide this method. So I get compiler errors.
As expected. This method is not in Java EE 5 (at least this is my understanding). So you need to use:
ExpressionFactory factory = new ExpressionFactoryImpl();
The official Java EE 6.0 jar provided by maven (java.dev.net) contains this method.
Yes, because this is Java EE 6, because EL is now standalone, with its own specification (technically, EL is still in JSR-245, sorry if this is confusing). So Java EE 6 includes EL 2.2 (yes, the version jumped from 1.1 to 2.1.2 and then 2.2 for a better alignment with the JSP version). And this version does expose the newInstance() methods on ExpressionFactory.
Why don't you want to use the libs from a Java EE server ? You'll eventually have to test in one, even if locally. You could use Tomcat, it's easy to install and to use.
In Tomcat for example, all the jars providing the Java EE api are available in the lib folder. If you compile using those libs, and stick to the standard Java EE API, your code will be compatible with all servers that implement the Java EE API.
If you use Maven and don't want to have these libs in your arborescence, and have a server installed, you can use the system dependency type (see here for more informations)