I have created a module com.company.ep that is located in the source folder com.company.ep. (Yes, I have removed src from the build path and deleted it!) Inside the source folder, I have a couple of packages as the following:
com.company.ep <--- root source folder
com.company.ep.main <--- package 1
com.company.ep.model <--- package 2
com.company.ep.view <--- package 3
// ... more packages
module-info.java
The main class is located in the package com.company.ep.main.Main. In my module-info.java, I have configured the dependencies:
module com.company.ep {
exports com.company.ep.main;
exports com.company.ep.model;
exports com.company.ep.view;
// ... more exports
requires javafx.controls;
requires javafx.graphics;
}
When I tried to launch my program, eclipse told me that:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.controls not found, required by com.company.ep
So, I tried to run it on the command prompt:
java -p d:\Applications\openjfx-sdk-11\lib;bin -m com.company.ep/com.company.ep.main.Main
bin is the output folder of eclipse, and it worked.
So, I went to Properties → Run/Debug Settings → Main → Show Command Line, it showed:
D:\Applications\openjdk-11.0.1\bin\javaw.exe -Dfile.encoding=UTF-8 -p "D:\Development\Eclipse-Workspace\MyProject\bin" -classpath "D:\Applications\openjfx-sdk-11\lib\javafx.base.jar;D:\Applications\openjfx-sdk-11\lib\javafx.controls.jar;D:\Applications\openjfx-sdk-11\lib\javafx.fxml.jar;D:\Applications\openjfx-sdk-11\lib\javafx.graphics.jar;D:\Applications\openjfx-sdk-11\lib\javafx.media.jar;D:\Applications\openjfx-sdk-11\lib\javafx.swing.jar;D:\Applications\openjfx-sdk-11\lib\javafx.web.jar;D:\Applications\openjfx-sdk-11\lib\javafx-swt.jar" -m com.company.ep/com.company.ep.main.Main
I have created a user library with all JARs added, and the library is added to the project's Modulepath.
Then I have tried to set the module path explicitly in VM arguments in Run/Debug Settings: -p D:\Applications\openjfx-sdk-11\lib, I'd still no luck.
My questions are:
Why javaw.exe?
Why classpath? As my library is added as a module-path entry.
How to configure the module dependencies in eclipse.
I am not sure if I have configured eclipse correctly, or whether it is probably a problem of OpenJDK as it worked when I worked on another computer with Oracle Java SE installed.
Thank you!
The explanation of why Eclipse fails on running your modular project can be found in the OpenJFX docs for Eclipse (modular from IDE section).
As it was already mentioned:
Being a modular project, and since we already added the JavaFX SDK library to the module-path, there is no need to add any VM arguments.
But if you run on Eclipse you will get the mentioned error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Module javafx.graphics not found, required by hellofx
So why is it failing??
As explained in the docs:
This exception happens because the Eclipse ant task overrides the module-path
How does this happen??
Checking the command line applied (Show Command Line from Run Configurations...), you can find out why:
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 \
-p bin/hellofx \
-classpath $PATH_TO_FX \
-m hellofx/org.openjfx.MainApp
If you copy it and paste it and run it in a terminal, it will fail of course with the same message. The reason is that Eclipse doesn't add the JavaFX library to the module path.
If the task generates the wrong arguments, let's try to fix it by adding our own VM arguments by editing Run configurations... and adding -p $PATH_TO_FX:bin/hellofx.
But if you run it, it will fail again.
Let's check why, with Show Command Line from Run Configurations...
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 \
-p $PATH_TO_FX:bin/hellofx \
-p bin/hellofx \
-classpath $PATH_TO_FX \
-m hellofx/org.openjfx.MainApp
As you can see, the user's VM arguments are added before the default ant task arguments, so there are two -p (--module-path) options, and the first one (the user's one with the JavaFX jars) is overridden by the second one (only the project's module), so, again, the JavaFX jars are not added to the module path, and hence you get the error.
So how can we fix it??
As mentioned in the linked documentation, the possible fix is:
To prevent this issue click on Run -> Run Configurations... -> Java Application -> Dependencies, select Override Dependencies... and add -p /path-to/javafx-sdk-11/lib:bin/hellofx, and press Override.
With this solution, you can see it works, and you can check the command line:
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 \
-p $PATH_TO_FX:bin/hellofx \
-p bin/hellofx \
-classpath $PATH_TO_FX \
-p /path-to/javafx-sdk-11/lib:bin/hellofx \
-m hellofx/org.openjfx.MainApp
Basically we are adding again the "right" module path option, after all the failed ones.
While now the project runs, the solution is obviously not nice.
Here you can find a sample referred from the OpenJFX documentation.
EDIT
Based on #kleopatra comments, another workaround to make it work is the following:
For some reason, the library JavaFX11 (that contains modular jars) is not scanned and Eclipse doesn't include those jars into its -p option, but into the classpath:
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 \
-p bin/hellofx \
-classpath $PATH_TO_FX \
...
But, if you add those jars directly to the module path, it will do add them, and this will run fine:
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 \
-p bin/hellofx:$PATH_TO_FX/javafx.base.jar:...:$PATH_TO_FX/javafx.controls \
...
Then with this there is no more need to override the dependencies.
EDIT 2
As #mipa points out in a comment, there was a bug filed on this issue, and it has already been solved. I've tested it with Eclipse 2018-12 M2 (4.10.0M2) Build id: 20181108-1653, and it works with the JavaFX11 library only (as it should):
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 \
-p bin/hellofx:$PATH_TO_FX/javafx.base.jar:... \
-m hellofx/org.openjfx.MainApp
Related
I have written a Java 17 application that provides several MBeans. If I start the jar with a standard Java 17 SDK via java -jar myjar.jar the applications starts and I can connect to it from JConsole.
Then I have created a custom runtime image with jlink.
The application itself runs fine with this image. It gets the MBeanServer and registers successfully my MBean.
When I start Jconsole I can select the running application (as "Local Process") but then the connection to this process can't be created.
I have tried to add a number of additional modules (like jdk.management, java.management, ...) but without success. It seems that at least one module is missing because in my customer runtime image e.g. the DLL management_ext.dll is missng.
Any idea which modules are necessary?
Try use jdeps to check all modules are required in your build.
Example of listing all modules from .jar
jdeps --ignore-missing-deps --print-module-deps --multi-release 17 your-jar.jar
Example to jlink
jlink \
--module-path /path-with-all-jdk-modules \
--add-modules $(jdeps --ignore-missing-deps --print-module-deps --multi-release 17 your-jar.jar ) \
--output /path-output-jre-custom \
--strip-debug \
--no-header-files \
--no-man-pages \
--compress 2
I use jpackage (with JDK 14) for creating a standalone JavaFX application.
The output of jpackage looks strange, it consists of two the same copies of JRE and all files in app folder, except App.cfg file, can be deleted without any problem.
Does jpackage can do not generate unnecessary files?
What I have:
I have a simple project created from Maven archetype org.openjfx:javafx-archetype-simple:0.0.3.
And I just added maven-shade-plugin for creating jar with dependencies and a simple launching class for it (like NewMain class here).
I do:
mvn package
mvn javafx:jlink
jpackage --package-type app-image --dest targetApp --name App --runtime-image target/image --main-jar testApp-1.0-SNAPSHOT.jar --input target
As result I have two folders with JRE (absolutely the same ones):
targetApp\App\runtime
targetApp\App\app\image
And all files (and folders) (JRE (~53 MB), Jar (~9 MB), classes...) in targetApp\App\app can be safely deleted, except App.cfg file.
After deleting these files I run targetApp\App\App.exe and it works fine.
The deleting reduces the size of App from 118 to 56 MB.
An additional question: I use Windows and jpackage generates the result for Windows (a lot of dll files and exe), do I can create a standalone application in Windows for Mac and Linux?
You get this result because you already created an uber-jar which contains everything in addition to what you specified via --input target which, according to the documentation, has the following effect.
All files in the input directory will be packaged into the
application image.
Try whether it works to just remove the option --input target or don't create the uber-jar. Instead use the maven-dependency-plugin to copy all dependencies into a single folder, say target/libs, and then explicitly specify --input target/libs.
Your second question:
You cannot cross-create applications for other targets, if that is your question.
You might want to check out the JPackageScriptFX project on GitHub. It contains a sample multi-module maven project structure and build scripts for Mac and Windows that will build all available package types and executables for both platforms. You can find it here: https://github.com/dlemmermann/JPackageScriptFX
My solution without Oracle's jpackage: AdoptOpenJDK + jpackager + macOS => .pkg, .dmg
Download AdoptOpenJDK_13. Unzip and put into /Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk
Download jpackager for (in my case osx) from https://mail.openjdk.java.net/pipermail/openjfx-dev/2018-September/022500.html. Unzip.
Copy jdk.packager.jar and jpackager to the /Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/bin (!!!)
In /yourworkspace/target should be the programA.jar file. (In my case it is a small program created with OpenJFX + openjdk13)
The /yourworkspace/jlink denotes on your JRE with bin,lib etc. you might have created via jlink. (In my case I have my custom JRE + JavaFX modules)
The /yourworkspace/icons contains .icns .
create jpackager.command file in your workspace with the content:
#! /bin/bash
ABSPATH=$(cd "$(dirname "$0")"; pwd -P)
launcher=`ls $ABSPATH/target/*.jar`
for eachfile in $launcher
do
if [ -f "$eachfile" ];then
echo Creating .pkg ...
echo "$eachfile"
basename="${eachfile##*/}"
/Library/Java/JavaVirtualMachines/adoptopenjdk-13.jdk/Contents/Home/bin/jpackager \
create-installer \
--runtime-image $ABSPATH/jlink \
--name ProgramA \
--input $ABSPATH/target \
--main-jar $basename \
--version 1.0 \
--copyright "Nikita Gromov 2020" \
--name "ProgramA-macos" \
--mac-bundle-name "ProgramA" \
--output $ABSPATH/appimage \
--icon $ABSPATH/icons/20200220101822955_easyicon_net_32.icns
fi
done
Double click on jpackager.command which is located in /yourworkspace and wait until the jpackager has created ProgramA-macos-1.0.pkg and ProgramA-macos-1.0.dmg under /yourworkspace/appimage
My solution without Oracle's jpackage: AdoptOpenJDK + jpackager + Windows => .msi
Install WiX (!!!) Important step.
Download AdoptOpenJDK_11. Will be installed under C:\Program Files\AdoptOpenJDK\jdk-11.0.6.10-hotspot
Download jpackager (in this case win) from https://mail.openjdk.java.net/pipermail/openjfx-dev/2018-September/022500.html. Unzip.
Copy jdk.packager.jar and jpackager to the C:\Program Files\AdoptOpenJDK\jdk-11.0.6.10-hotspot\bin (!!!)
In /yourworkspace/target should be the programA.jar file. (In my case it is a small program created with OpenJFX + openjdk11)
The /yourworkspace/jlink denotes on your JRE with bin,lib etc. you might have created via jlink. (In my case I have my custom JRE + JavaFX modules)
The /yourworkspace/icons contains .icns .
create jpackager.bat file in your /yourworkspace folder with the content:
set openjdk=C:\Program Files\AdoptOpenJDK\jdk-11.0.6.10-hotspot\bin
set saveto=%cd%
cd %openjdk%
jpackager create-installer --runtime-image %saveto%/jlink --input %saveto%/target --main-jar ProgramA.jar --version 1.0 --copyright "Nikita Gromov" --name "ProgramA-win" --output %saveto%/appimage --icon %saveto%/icons/icon.ico --win-menu --win-shortcut --win-dir-chooser
Note The ProgramA.jar should be in /yourworkspace/target path (!!!)
Double click on jpackager.bat which is located in /yourworkspace and wait until the jpackager has created ProgramA-win-1.0.msi under /yourworkspace/appimage
Custom JRE + JavaFX mods on Windows
Create /yourworkspace/jlink.bat file. The content of it should be:
SET openjdk=C:\Program Files\AdoptOpenJDK\jdk-11.0.6.10-hotspot\bin
SET fx=C:\Programme\AdoptOpenJDK\javafx-jmods-11.0.2
set saveto=%cd%
cd %openjdk%
jlink --module-path %fx% --add-modules=javafx.base --add-modules=javafx.controls --add-modules=javafx.fxml --add-modules=javafx.graphics --add-modules=javafx.web --add-modules=javafx.media --add-modules=javafx.swing --bind-services --output "%saveto%\jlink"
This creates the /yourworkspace/jlink folder with a custom JRE+JavaFX libraries which you will link to jpackager.
I have gone through the java 9 jigsaw tutorial. I have been struggling to run class, java throws below error-
java --module-path mods -m mods/com.test/com.test.HelloWorld
Error occurred during initialization of boot layer
java.lang.module.FindException: Module mods not found
Javac command-
javac -d mods --module-source-path src $(find src -name '*.java')
I am using mac, java version-
$ java -version
java version "9"
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
Am I missing anything?
Remove additional mods from module name-
java --module-path mods -m com.test/com.test.HelloWorld
The -m flag accepts the module name and the main class you want to run. The module name is com.test, hence the command to run the class should be:
java --module-path mods -m com.test/com.test.HelloWorld
The --module-path mods tells java where to search for to find com.test.
When you first compiled your code using javac command as-
javac -d mods --module-source-path src $(find src -name '*.java')
What you ensured using -d directory was that to
Set the destination directory for class files.
in your case the mods folder where
If a class is part of a package, then javac puts the class file in a
subdirectory that reflects the package name and creates directories as
needed.
Hence you can take a look at the mods directory after executing the command, the .class for all(*.java) would exist in the corresponding directory structure as of their package name.
Then java tool option --module-path module path or -p module path specified in your next command :
Searches for directories from a semicolon-separated (;) list of
directories. Each directory is a directory of modules.
Your listed directory according to which is mods, assuming which you must have created following the getting started link.
Followed by --module modulename[/mainclass] or -m module[/mainclass] in your command
Specifies the initial module to resolve and the name of the main class to execute if not specified by the module.
which in your case is the module name com.test and the main class com.test.HelloWorld.
Hence the complete correct syntax of the command shall be:-
java --module-path mods -m com.test/com.test.HelloWorld
^ ^ ^
module directory module name main class
Thanks for the info
2 things I was doing incorrectly
1) Using the package path again like below
module\package\package.class
We should not retype the package path while executing the class.
2) Using the dos styled backslash instead of forward slash. We should always use the forward slash (/) to separate module with the class even you are executing in windows environment.
module/package.class
I'm trying to package two symlinks to corresponding jars provided by external dep1.rpm and dep2.rpm. These are declared as dependencies in my-app-extra.spec:
Requires: dep1
Requires: dep2
I have my %install symlinking their jars (%dep1jar, %dep2jar):
%install
%{__install} -d -m 0755 $RPM_BUILD_ROOT%{_javadir}
%{__install} -d -m 0755 $RPM_BUILD_ROOT%{_javadir}/%{my_app}
pushd $RPM_BUILD_ROOT%{_javadir}/%{my_app}
for jar in %dep1jar %dep2jar
do
ln -sf ../"${jar}" "${jar}"
done
popd
but the rpmbuild fails with:
ERROR: link target doesn't exist (neither in build root nor in installed system):
/usr/share/java/my-app/dep1.jar -> /usr/share/java/dep1.jar
Add the package providing the target to neededforbuild and Requires
// same error for dep2.jar
error: Bad exit status from /var/tmp/rpm-tmp.31253 (%install)
Is there any way to circumvent this rpmbuild check?
Background
I have a java application that (optionally) requires two external libraries to provide extended functionality. To install these libraries, I have created dep1.rpm and dep2.rpm that store the jars under %_datadir/java and an additional my-app-extra rpm that should symlink those under %_datadir/java/my-app (following some apparently established java-packaging conventions under linux).
But I'm failing to find how to force rpmbuild to build this rpm without declaring the external libraries as BuidRequires and having them installed first.
What I want
This is in summary what I'm after (simplified, as the complete solution involves versioning):
/usr/share/java/dep1.jar (from dep1.rpm)
/usr/share/java/dep2.jar (from dep2.rpm)
/usr/share/java/my-app/dep1.jar -> ../dep1.jar (from my-app-extended.rpm)
/usr/share/java/my-app/dep2.jar -> ../dep2.jar (from my-app-extended.rpm)
Note: I'm now exploring the possibilities of rpm subpackages, but I somehow expect this to be possible without subpackaging.
I could make it work 'touching' the targets and excluding them from the files. In my-app-extra.spec:
%install
%{__install} -d -m 0755 $RPM_BUILD_ROOT%{_javadir}
%{__install} -d -m 0755 $RPM_BUILD_ROOT%{_javadir}/%{my_app}
pushd $RPM_BUILD_ROOT%{_javadir}/%{my_app}
for jar in %{dep1jar} %{dep2jar}
do
# touch! rpmbuild aborts the build if symlink targets missing!
touch ../"${jar}"
ln -sf ../"${jar}" "${jar}"
done
popd
# more stuff ...
%files
# ...
# Exclude dummy (touched) files!
%exclude %{_javadir}/%{dep1jar}
%exclude %{_javadir}/%{dep2jar}
%{_javadir}/%{my_app}/%{dep1jar}
%{_javadir}/%{my_app}/%{dep2jar}
According to Pitest's documentation, it seems that this should be simple, but it is giving me some trouble. I should be able to have
java -cp <your classpath> \
org.pitest.mutationtest.commandline.MutationCoverageReport \
--reportDir c:\\mutationReports \
--targetClasses example.foo.* \
--sourceDirs c:\\myProject\\src \
--targetTests example.foo*
but I don't know what some of those things should be for my project, such as "<your classpath>".
My project's file structure looks like this:
Ultimately I want to put this in a .bat file and run it on TeamCity for my CI
Any help would be appreciated!
The command line parameter should cover every single jar you would need to build your project (when making the project inside an IDE it should provide a classpath for you that you can use in command line).