I have written JavaFX app with Maven, now I want to convert it to executables. I was successful at generating .exe file for Windows using launch4j-maven-plugin, for mac I'm using appbundle-maven-plugin, it generates .app, but it doesn't work (for M1), saying JRELoadError, I think it's because of my cpu architecture as I'm not using x86 one, I've tried with few versions of jdk, including one that I use to launch it in IntelliJ.
So my complete question is this: How to get M1 mac compatible .app from Java GUI Maven project? (I prefer to have as a Maven plugin if possible).
You could earn yourself a few bonus points by giving this https://github.com/dlemmermann/JPackageScriptFX little framework a try. I don't have an M1 Mac, so I cannot try it myself but in principle this should work with maybe a few tweaks. You may have to upgrade to the latest EA builds of Java 18 and also JavaFX 18 because there have been some recent bug fixes.
Disclaimer: I am biased because I developed this framework together with Dirk.
Related
Following this question Gluon Mobile project does not work with gradle 6, I want to know how to ship an application that uses gluon mobile and Java 14.
From what I read, gluon mobile only supports Java 14 if I use GraalVM with the client plugin (https://github.com/gluonhq/client-maven-plugin or https://github.com/gluonhq/client-gradle-plugin). I read https://github.com/dlemmermann/JPackageScriptFX to learn how to package a JavaFX app, but I don't think it's compatible with GraalVM's native image.
So it looks like I'm stuck. I can't use jpackage/link script above because I can't use Java 14, and if I use the client plugin with GraalVM to be able to use Java14, I can't use the jpackage/link script. How do I ship then?
Can I just ship a zip/jar with my whole gluon mobile app and the JDK module deps maybe? Then I won't need platform specific images or packaging.
My target platforms for now are Win and Mac, at least until I figure this thing out. I'm aware that everything here is quite new, so I'm not looking for miracles.
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 have an assignment for my school that I have to submit that needs you to create a Java application that involves recursion, file read, and javaFx. I have a 15 inch MacBook Pro with an i7 processor. When I try to use JavaFx in a class in Java, I always get errors saying that javaFx.application.Application or javaFx.scene.Scene cannot be applied to a type. Basically, my Java oxygen application cannot run javaFx. I've tried multiple YouTube videos on how to download plugins from oracle and the Java oxygen marketplace. I told my instructor and he hasn't gotten back to me yet. Everytime I download a possible plugin like e(fx)clipse/2.0.0/ (or something like that), Java oxygen sends a message that it cannot complete the operation because new software has already been installed. I kept searching oracle for the latest JDK but javaFx still won't download. I was just wondering if it had to do with me having an Apple and not Windows computer or is there something else I can try. Thanks for your help!
Just go here and download the Mac version of the JDK and install it.
http://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html
That is all which is technically needed to run a JavaFX application. You should also download and install the latest version of Eclipse (Photon) because it fixes some problems with the latest Java.
http://www.eclipse.org/downloads/index-developer.php
If you like you can also install e(fx)clipse from the marketplace but it is not needed to write JavaFX applications.
My application is based on Eclipse 3.8, and I'd like to know if it will run over Java.
I'm not using a newer version because it has performance issues. From my experience, Eclipse 3.8 is a lot faster compared to any newer versions of Eclipse.
Does someone know something about this?
UPDATE: The previous title may suggest that I want Eclipse 3.8 to be able to support the new features of Java 9. But, I really just want to know if I'll be able to run the application over Java 9 JRE.
Yes it works, but only with a small patch.
It fails because the org.eclipse.osgi bundle of Eclipse 3.8 (Juno) has no runtime profiles for Java 8 or Java 9. If you add those it works for me.
I made successful tests with an RCP-based app on target plattform 3.8.2 (http://archive.eclipse.org/eclipse/downloads/drops/R-3.8.2-201301310800/) running under Java 9 Oracle JVM under Windows 7.
What to do:
You have to patch the org.eclipse.osgi bundle:
strip signing information
manually add an entry for the Java 9 Runtime Enironment in the profile.list of the bundle and add a JavaSE-1.9.profile definition
E.g.: https://github.com/derWallace/org.eclipse.osgi
But no guarantees that this is a good deal for production!
No. Oxygen (4.7) and newer only is what's planned. If your performance findings are verifiable and repeatable, file bug reports about them.
I have used these three open source tools for packaging my java apps, but they all look like abandon-ware now. All three are very good pieces of software. What are the options now? (or is using Java for desktop app development no longer a "hot" market for app developers to build & maintain these tools?).
1) exe wrapper:
jsmooth - no new development in 2.5 years - does not support 64 bit.
launch4j - no new development in over a year, supports 64 bit, but you can't sign the exe created by launch4j, so I prefer jsmooth, but it does not support 64 bit.
2) onejar:
It works, but there has been no new development or web site update in more than 2.5 years. So, just want to switch to something that's supported / have a backup plan if it suddenly breaks with a new build of Java.
Thanks
Edgar
Launch4j has just been updated ! http://launch4j.sourceforge.net/changelog.html
Did you check IzPack? This is a great piece of software to create cross-platform installers:
IzPack is an installers generator for the Java platform. It produces lightweight installers that can be run on any operating system where a Java virtual machine is available. Depending on the operating system, it can be launched by a double-click or a simple 'java -jar installer.jar' on a shell. The most common use is to distribute applications for the Java platform, but you can also use it for other kinds of projects. The main benefit of IzPack is that it provides a clean and unique way of distributing a project to users using different operating systems.
Some really famous companies and projects use it for many years (Sun Microsystems, JBoss/RedHat, the Scala language project, some ObjectWeb/OW2 projects, XWiki and many more). If it's good for them, it should be good for you :)
Since none of the answers were approved, and JavaFX 2.2 has not been mentioned above (was not available at the time of the answers) here goes:
JavaFX 2.2 (part of Java Runtime and SDK since 7u6) allows building native exe/dmg/rpm's that tag along the full RT component as well. I believe this is a valid answer to your need, as well as an officially supported solution from Oracle.
https://blogs.oracle.com/talkingjavadeployment/entry/native_packaging_for_javafx
Have you tried IzPack (http://izpack.org/)?
You can try
http://winrun4j.sourceforge.net/
Has an exe with 64bit support and is quite easy to configure with an ini file.
As I was fed up with recent security changes in Java Webstart, I created my own tool, JNDT. It's under GPL.
It goes farther than akauppi's suggestion because it allows to create GNU Linux packages even under Mac and Windows :) I use it to create Mac bundle under GNU Linux too. For the moment, it's just a single Ant library with a few dependencies that allows to create native self-contained application bundles for GNU Linux, Mac OS X and Windows. I use it for my first person shooter and I'm very happy with it. It bundles the JRE but it can use the system JRE if you want.
P.S: JNDT is able to create a native Windows installer as an executable with NSIS even under GNU Linux.
I understand that the GPL license discourages some developers to use my tool. In this case, rather use PackR.
Maven 2 provides the ability to create a jar which contains all the dependencies as part of its assembly plugin. This combined with the jar plugin configuration of the manifest file (and specifically setting Main-class to the Class with main) is all you need to do basic packaging.
To some extent Java web start is now considered the better way to distribute Java applications and Maven 2's assembly capability combined with web start gets you everything you need without going via the exe route.
If you just want an exe (instead of a full-blown installer) you can make one with NSIS:
http://nsis.sourceforge.net/Java_Launcher_with_automatic_JRE_installation
Yes, NSIS is an installer but you can have it just run a jar in the same directory by stripping out all of the installer stuff. Basically it works like launch4j but is a lot more configurable.
If you are using gradle, there is a plugin that uses launch4j (under the hood) and works great. It doesn't even require you to download or install launch4j, it is totally automated.
https://github.com/TheBoegl/gradle-launch4j