How to build real desktop executable application from JavaFX 11 project? [duplicate] - java

This question already has answers here:
Bundle JavaFX app with openjdk 11 + runtime
(5 answers)
Closed 3 years ago.
I have written a new JavaFX 11 project. This project is modular and uses JavaFX 11 & JDK 11 too. It doesn't include any build tools such as Maven or Gradle or something else. Now the project has been completed and I'm trying to package it as an executable application for Windows platform (.exe file with dependencies). Anybody could help me with the solution or documentation references??

The first question is why do you start a new project based on the outdated Java 11 and even worse JavaFX 11? The current version of Java is 13 (and 14/15 already availabe as EA releases) and the current JavaFX version is also 13 (and 14 as EA). If it absolutely has to be Java 11 you can still combine that with the latest JavaFX release. So, 11/13 or even 11/14 would be ok.
In order to answer your question: If you were willing to switch to Java 14 you could directly use the new jpackage tool which is included in this release to build an exe and because your project is modular it would be just calling a single command.

Related

How to properly step by step install java and javafx in Intellij on Linux? [duplicate]

This question already has answers here:
IntelliJ can't recognize JavaFX 11 with OpenJDK 11
(7 answers)
Closed 3 years ago.
I think I am not alone who doesn't know how to properly download Java and JavaFX on Linux. And how make it works in IntelliJ Idea
So my questions are:
I'm looking for Java JRE or Java SDK?
Must Java and JavaFX be at same version?
How I will connect it with IntelliJ
Do I have to write something like in windows "path variable"?
Maybe this is not proper question, because it was answered somewhere else, but I dont undrestand basic things about installation of Java. Thanks everyone.
1) JRE is a Java Runtime Environment - enough for Java code to run but not enough to develop code. What you need is JDK (Java Development Kit), you can download it here https://www.oracle.com/technetwork/java/javase/downloads/index.html
2) No, they don't need to be the same version
3) Follow these steps: https://openjfx.io/openjfx-docs/#maven
I prefer doing it with Maven (less hassle) but you can find easy to follow explanations for both on that page
4)Yes in linux you need to add Path variable as well - here are the instructions:
https://www.baeldung.com/linux/path-variable

e(fx) clipse doesn't work on fresh macOS Mojave Java 11 [duplicate]

This question already has answers here:
How to add JavaFX runtime to Eclipse in Java 11?
(6 answers)
Closed 4 years ago.
I just installed the newest Eclipse and e(fx)clipse, but it didn't change anything - I have no idea why javafx imports are not resolved.
Sorry I can't provide more proves I tried to solve it, but I just think (and remember it was I like that before) installing it and restarting Eclipse should be sufficient.
The purpose of e(fx)clipse is not to resolve JavaFX imports. If using Java 11 or higher, you have to add the JavaFX dependency yourself because JavaFX has been removed in Java 11. See Java 11 release notes:
JavaFX is no longer included in the JDK. It is now available as a
separate download from openjfx.io.
See: Getting Started with JavaFX 11
e(fx)clipse offers as a runtime e. g. a way to build JavaFX OSGi/Eclipse-based applications and provides tooling for JavaFX, e. g. to edit FXML files.

JavaFX Java 11 and beyond [duplicate]

This question already has an answer here:
JavaFX applications built to target Java 8 - How to keep running with Java 11?
(1 answer)
Closed 4 years ago.
Many work environments continue to stay on JRE8 -- I'm a little confused on how to proceed with developing for the latest versions of Java. I compile JavaFX applications with Java SE 8 using NetBeans 9. Is there a way for me to start distributing via JDK 9, 10, and 11+ but still keep it compatible with all the JRE8 environments?
Or once I compile via JDK11, will it only be compatible when or if an environment upgrades their runtime? Or can I distribute a completely separate jar that runs without the need for a JRE and start today (even if they stay on JRE 8)?
There is a break between Java 8, and the modular Javas 9+. Though the module system has support for combined non-modular and modular code, JavaFX becomes OpenJFX, and I would not rely on there being one code base for long.
Also mind that modular means you can deliver your application with JRE parts as a small standalone executable.
So develop in Java 11+, possibly "convert" the sources to java 8 with a small tool written yourself. Restrict the usage of var and other short-cuts. (Maybe develop in java 8 and convert to Java 9+?).

How do I use JavaFX 11 in Eclipse?

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!

Can a java8 compiled jar file run on java7? [duplicate]

This question already has answers here:
Can Java 8 code be compiled to run on Java 7 JVM?
(5 answers)
Closed 5 years ago.
I have a jar file in that some features only belong to java 8(for ex lambda expression), so it is compiled in java 8. Same jar has some features belong to both java 7 and java 8. Now i want that when user run this jar in java 7 , java 7 related classes should work as he/she only wants functionality that work on java 7 only. If he/she wants the functionality related to java 8 , he will run it with java 8.
This java 8 compiled jar should not give an error of "Lambda expressions are allowed only at source level 1.8 or above". And i don't want to create separate jars for java 8 and java 7 users.
Unfortunately not, multi-release jars allow this, they are a new feature in Java 9, but multi-release jars do not go back to java 7, however they will work for future java releases.
Multi-release Jars

Categories

Resources