Java FX Application with Jpackage not work - java

I've created my Application in JavaFX. Everything works well, so I use the Jpackage to make a installable version of my application in Window.
After I install the package, the window computer still ask to install JVM.
jpackage -t exe --name "FReport" --description "Time reporting" --app-version 1.0 --input "C:\myapp" --dest "C:\myapp\out" --main-jar "freport.jar" --module-path "C:\Program Files\Java\javafx-sdk-17.0.1\lib" --add-modules javafx.controls,javafx.fxml --win-shortcut --win-menu
My expectation, that I can use Jpackage to install my JavaFX application on any computer and it automatically setup the JVM ..etc. The user just have to click on the icon and run the application.
Any suggestion on the correct command in Jpackage to pack my JavaFX application jar file with all the require environment like JVM ..etc

You have not specified the correct modules for JavaFX - you have referenced the lib files not modules so jlink won't contain the JavaFX libraries because it does not read the modules such as javafx.base.jmod. Download jmods JDK and reference C:\somepath\javafx-jmods-VER instead of the lib release.
Additionally: turn on console by adding --win-console and report back what the actual error messages are when your run the installer and the application EXEs.
You have specified --input with nested --dest inside, so you will get your whole application copied into the second release
Test your application with the installed runtime image, or as separate image (see below). Simply reference the installer location of jlink runtime with your current application to see which modules are missing.
If you don't update -app-version each time then the new package is NOT installed by any of the subsequent attempts unless you un-install the previous installation. This is very frustrating, jpackage ought to warn on re-install same version rather than give up with no error message.
Note all of these other typical jpackage issues:
Enable console
update version number each run
minimise
use manual jlink to create JavaFX JRE, then you can test the JRE before running jpackage

Related

How to install Jar (java) to NVIDIA-Docker image or NVIDIA-Docker dependencies to Java image?

I have to bundle up my system using Docker. But my system uses Java (JAR file to run) and python with PyTorch. I initially tried to use openjdk:buster base Docker image and then installed python3 on top of it. So both JAR and PyTorch worked, but PyTorch is only CPU supportive. But now I have to speed-up my PyTorch code using GPU, and for that I need NVIDIA-Cuda. In a separate Docker, I found nvidia/cuda:10.2-base-ubuntu18.04 works for my PyTorch. But this Docker can't run JAR file.
So I am stuck in combining these 2. I either want to
install NVIDIA-Cuda dependencies to openjdk Docker base image
install openjdk (openjdk-14) dependencies to NVIDIA-Cuda Docker base image
Anyone has any suggestions on how I can do that or any alternative hacks ?
You can have a single image, instead of two by creating your own docker image that uses the nvidia image, and install java on it. I.e. have a Dockerfile as below
FROM nvidia/cuda:10.2-base-ubuntu18.04
RUN apt-get update
RUN apt-get install openjdk-14-jdk
COPY <your jar file> <a path>
CMD [ "java" "other java flags/args>" "-jar" "<path to your jar file>"]
run docker build on that Dockerfile, and docker run as you normally would, and your java code should have access to NVIDIA-Cuda. (Also note, some prefer ENTRYPOINT to CMD)

Asking JRE to run a jarfile on launching the java.exe

I'm creating a game compatible with Discord's Rich Presence, and as Discord uses exe files to launch games, when I'm trying to launch my game from Discord, it starts the java.exe executable coming from the JRE instead of the jarfile of my game.
What I'm asking is, is there any way to copy jre (to bundle it with the game) and setup it to start automatically a specific jarfile ? If yes, how ?
If it's not possible, is there any way to launch a jar from an exe without launching java.exe separately ?
Thanks for your help.
Sorry for bad English, I'm french
Java 14 includes a packaging tool that allows exactly that. There are also tutorials available on how to do that, e.g. here. In short, something like this should work:
jpackage --input target/ \
--name MyApp \
--main-jar myApp.jar \
--main-class com.company.MyApp \
--type exe \
--java-options '--enable-preview'
If you are not yet using Java 14 but an older version, have a look at WinRun4J or Launch4J. Both allow creating exe-wrappers for Jar-Files, or creating an exe-file along with a JRE and a jar-File to run it independently. Those two only work for Windows, whereas the Java packaging tool will create executables for each platform (Windows, macOS, Linux) when run on the respective platform (it's not cross-platform capable, e.g. creating a macOS executable on Windows).
For macOS, there is appbundler which is able to create a .app with JRE and jar-File included, so users can just double click the application to start the java application.

Add JavaFX jmods to java --list-modules

Preface:
I need to open .jar files which requires Java and JavaFX. I have installed both Java (from Oracle website) and JavaFX (SDK from openjfx website). I have added environment variables by updating /etc/environment file, and adding JAVAFX_HOME="path/to/JavaFX".
/etc/environment file looks like:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk-12.0.2/bin"
JAVA_HOME="/usr/lib/jvm/jdk-12.0.2"
JAVAFX_HOME="/home/joshi/Documents/javafx-sdk-12.0.2/lib"
For now, I can get a .jar file running by executing:
java --module-path $JAVAFX_HOME --add-modules ALL-MODULE-PATH -jar myfile.jar
There are multiple .jar files, which makes executing above command pretty troublesome. Name of .jar files are pretty non-catchy and complex too.
Question:
I want to know if I can add JavaFX jmods to Java permanently. For example, when we execute in terminal java --list-modules, it should include JavaFX mods in it too.
I have tried:
Copying JavaFX jmod files in /usr/lib/jvm/jdk-12.0.2/jmods. But even after rebooting, java --list-modules doesn't include JavaFX mods. I have also ran
sudo update-alternatives --config java
sudo update-alternatives --config javac
I don't think creating .sh script files would be a great idea as there would need to be as many script files as there are .jar files.
Any help is highly appreciated. I am on Kubuntu.
You can use environment variable: _JAVA_OPTIONS.
All options specified in this variable will be appended to the JVM startup args.
export _JAVA_OPTIONS="--module-path=/path/to/JavaFX --add-modules=ALL-MODULE-PATH"
Do not download and install the SDK zip file. Instead download and install the jmods zip file.

Javapackager tool from command-line on OSX?

javapackager and javafxpackager don't seem to be recognised on the command line for me. They don't show up in the terminal, even after I installed the latest 1.8 SDK. (Even 'echo $JAVA_HOME' seems to be drawing a blank, though java -version seems to work fine.)
If I look under /Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/ I can see the javapackager and javafxpackager tools are present, but if I follow /usr/libexec/java_home back to it's origin in /System/Library/Frameworks/JavaVM.framework/Versions/A/Commands/ , there's no sign of them.
The only other discussions I could find on the subject were a blog post and mailing list from about a year and a half back:
https://devreboot.wordpress.com/2014/11/26/java-desktop-app-packaging-automation/
http://lists.apple.com/archives/java-dev/2015/Nov/msg00009.html
I realise OSX hasn't come with java 'by default' for some time, but that's kinda why I was hoping to release my application as a self-contained bundle with it's own VM. Would it be standard procedure to update my bash profile to point at the tool explicitly? Is there something screwy about my personal setup, or is there some gap in the tool support on OSX?
PS: I realise there's an older thread on this subject below:
What is the best way to deploy JavaFX application, create JAR and self-contained applications and native installers
However, that describes javapackager as a .jar file, and whatever I've got doesn't seem to be a .jar file. I'm legitimately confused about what I'm supposed to do with it.
EDIT: Thanks to everyone for the tips- I think I have enough info to go on for now.
You could try this gist for building, packaging and running a test install on Java client apps from the OS X command line. No guarantees it will work for you, it was just something I whipped up for personal development purposes a long time ago. But, the info in there may help in resolving packager tool locations from the command line and also in performing other packaging related functions.
The key part for locating (and using) the javapackager is:
# select java version
export JAVA_HOME=`/usr/libexec/java_home -v 1.8`
$JAVA_HOME/bin/java -version
...
# make an executable jar file
$JAVA_HOME/bin/javapackager -createjar -srcdir . -appclass start.HelloWorldSwing -srcfiles HelloWorldSwing.jar -outdir . -outfile HelloWorld.jar
# package the jar and java runtime as a native application with installer
$JAVA_HOME/bin/javapackager -deploy -srcdir . -srcfiles HelloWorld.jar -outdir . -outfile HelloWorld -appclass start.HelloWorldSwing -native -name HelloWorld
Note, the above is for packaging a Swing application. Packaging a JavaFX application will use slightly different command line options for the packager.
Doing things this way from command line scripts is decidedly old school, usually maven or gradle is used.
My personal preference would be to just use Ant, but I guess that's only slightly less old-school?
Yes, not that there is anything wrong with that. Documentation on using Ant to package java client applications is provided by Oracle.

How to Run a Java Project on Linux Without Using IDE

I am new to Java.
Basically, I developed a java projects which contains multiple Java packages inside Eclipse. The project runs OK on my desktop with a redhat Linux installed. However, I need to run it on a more powerful Linux server (redhat enterprise Linux) which does not have X11 installed. Therefore, it is impossible to run Eclipse on that server.
Is it possible to do that? If so, how can I move the entire project to that server including the input and output folders?
Thanks
In Eclipse use the "Export Runnable Jar" option. Highlight your project then click file->Export, choose Java, choose Runnable Jar file. Otherwise you can also use the javac compiler to compile your project and run it with the java command and your main class.
You will need to install the JRE on the machine you want to run it on. This can be done with the following command:
yum install java-1.6.0-openjdk*
Once you have java then it is simply a matter of executing your application. I would recommend using eclipse to compile your project to a jar and use the following command to execute it:
java -jar *JarFileName*.jar
Running Java is nothing to do with Eclipse . You can run your java program in linux machine by opening terminal .
Step1;- Set your JAVA_HOME in your bash profile .
Step2:- open terminal , go to the folder or package where your main program is present.
Step 3:- compile it using javac -cp lib.jar Filename.java
Step 4:- After compilation class file will be available , run it using java filename.java
Usually IDE like eclipse is for development not for running the application , but Linux version of eclipse is also available
http://eclipse.org/downloads/?osType=linux

Categories

Resources