OS: Raspbian
CPU: RPi (armv7l)
JDK: Zulu11.31+16 (build 11.0.3+7)
JavaFX: self-built https://github.com/openjdk/jfx/archive/jdk-11+7.tar.gz
Problem:
$ export PATH_TO_FX=/usr/lib/jvm/javafx-sdk-armv6hf-11-0-7-b1/lib
$ ls $PATH_TO_FX
javafx.base.jar
javafx.controls.jar
javafx.fxml.jar
javafx.graphics.jar
javafx.media.jar
javafx-swt.jar
javafx.web.jar
<bunch of lib*.so>
$ jar -t --file $PATH_TO_FX/javafx.graphics.jar | grep Application
javafx.graphics/javafx/application/Application.class
$ export MODULES=javafx.controls,javafx.graphics
$ wget https://raw.githubusercontent.com/openjfx/samples/master/HelloFX/CLI/hellofx HelloFX.java
$ javac --module-path $PATH_TO_FX --add-modules $MODULES HelloFX.java
HelloFX.java:1: error: package javafx.application.Application does not exist
import javafx.application.Application
I've checked and double-checked $PATH_TO_FX, and $MODULES, they are seem to be correct. If i run javac with -verbose, than I see jdk modules loaded, but jfx are not.
Update, 2020.12.19:
Turned out the problem was my build of JavaFX SDK. For whatever reason Gradle
generated module jars with module name as the root folder. Once I stripped
module names and repacked jars SDK works fine. Looking into Gradle issue now.
Related
I have a runnable jar (drkodi-mac-aarch64.jar), that should contain all that is needed, including the FX components.
I can successfully start the app by executing the following command:
java -jar drkodi-mac-aarch64.jar
My java installation:
java -version
openjdk version "18.0.1" 2022-04-19
OpenJDK Runtime Environment Temurin-18.0.1+10 (build 18.0.1+10)
OpenJDK 64-Bit Server VM Temurin-18.0.1+10 (build 18.0.1+10, mixed mode)
Now, I bundle this runnable jar into a Mac App, which contains a JRE and a launcher.
file DrKodi.app/Contents/MacOS/launcher-macosx-aarch64.sh
DrKodi/DrKodi.app/Contents/MacOS/launcher-macosx-aarch64.sh: POSIX shell script text executable, ASCII text
cat DrKodi.app/Contents/MacOS/launcher-macosx-aarch64.sh
cd "$(dirname "$0")" || exit
../Plugins/jre/Contents/Home/bin/java -jar "../Resources/Java/drkodi-mac-aarch64.jar"
The JRE is located here:
DrKodi/DrKodi.app/Contents/PlugIns/jre/Contents/Home
It is created using the following command:
Creating JRE with next modules included: java.base,java.logging,java.desktop,jdk.unsupported,java.scripting
[INFO] Using /Library/Java/JavaVirtualMachines/temurin-18.jdk/Contents/Home/jmods modules directory
[INFO] Executing command: /bin/sh -c cd '/Users/alex/sources/drkodi/.' && '/Library/Java/JavaVirtualMachines/temurin-18.jdk/Contents/Home/bin/jlink' --module-path /Library/Java/JavaVirtualMachines/temurin-18.jdk/Contents/Home/jmods --add-modules java.base,java.logging,java.desktop,jdk.unsupported,java.scripting --output /Users/alex/sources/drkodi/target/DrKodi/DrKodi.app/Contents/PlugIns/jre/Contents/Home --no-header-files --no-man-pages --strip-debug --compress=2
[INFO] Removing folder [/Users/alex/sources/drkodi/target/DrKodi/DrKodi.app/Contents/PlugIns/jre/Contents/Home/legal]
[INFO] JRE bundled in /Users/alex/sources/drkodi/target/DrKodi/DrKodi.app/Contents/PlugIns/jre/Contents/Home!
Now, when I start the App using the bundled java executable, like this:
./DrKodi.app/Contents/PlugIns/jre/Contents/Home/bin/java -jar ./DrKodi.app/Contents/Resources/Java/drkodi-mac-aarch64.jar
I get the following exception:
java.lang.RuntimeException: No toolkit found
at com.sun.javafx.tk.Toolkit.getToolkit(Toolkit.java:280)
at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:291)
If I start the jar file using my installed JRE, like follows, it works:
java -jar ./DrKodi.app/Contents/Resources/Java/drkodi-mac-aarch64.jar
If I take a look at the runnable jar, the library seems to be there, it's also the right arch:
unzip -l drkodi-mac-aarch64.jar | grep javafx
1659 10-25-2019 15:22 BOOT-INF/lib/javafx-weaver-spring-boot-starter-1.3.0.jar
5686 10-25-2019 15:23 BOOT-INF/lib/javafx-weaver-spring-1.3.0.jar
9621 10-25-2019 15:23 BOOT-INF/lib/javafx-weaver-core-1.3.0.jar
3918 10-25-2019 15:24 BOOT-INF/lib/javafx-weaver-spring-boot-autoconfigure-1.3.0.jar
302 10-17-2022 11:07 BOOT-INF/lib/javafx-fxml-19.jar
129499 09-12-2022 11:46 BOOT-INF/lib/javafx-fxml-19-mac-aarch64.jar
306 10-17-2022 11:07 BOOT-INF/lib/javafx-controls-19.jar
2547893 09-12-2022 11:46 BOOT-INF/lib/javafx-controls-19-mac-aarch64.jar
306 10-17-2022 11:07 BOOT-INF/lib/javafx-graphics-19.jar
4812958 09-12-2022 11:46 BOOT-INF/lib/javafx-graphics-19-mac-aarch64.jar
302 10-17-2022 11:07 BOOT-INF/lib/javafx-base-19.jar
752442 09-12-2022 11:36 BOOT-INF/lib/javafx-base-19-mac-aarch64.jar
This is strange to me, since the bundled JRE was created from my local Java installation, it should be the same.
The JavaFX libs are inside the runnable jar, the app is not modular, so it is a little strange that it works one way but not the other.
I am on a Mac M1.
Modules known to my installed JRE:
java --list-modules
java.base#18.0.1
java.compiler#18.0.1
java.datatransfer#18.0.1
java.desktop#18.0.1
java.instrument#18.0.1
java.logging#18.0.1
java.management#18.0.1
java.management.rmi#18.0.1
java.naming#18.0.1
java.net.http#18.0.1
java.prefs#18.0.1
java.rmi#18.0.1
java.scripting#18.0.1
java.se#18.0.1
java.security.jgss#18.0.1
java.security.sasl#18.0.1
java.smartcardio#18.0.1
java.sql#18.0.1
java.sql.rowset#18.0.1
java.transaction.xa#18.0.1
java.xml#18.0.1
java.xml.crypto#18.0.1
jdk.accessibility#18.0.1
jdk.attach#18.0.1
jdk.charsets#18.0.1
jdk.compiler#18.0.1
jdk.crypto.cryptoki#18.0.1
jdk.crypto.ec#18.0.1
jdk.dynalink#18.0.1
jdk.editpad#18.0.1
jdk.hotspot.agent#18.0.1
jdk.httpserver#18.0.1
jdk.incubator.foreign#18.0.1
jdk.incubator.vector#18.0.1
jdk.internal.ed#18.0.1
jdk.internal.jvmstat#18.0.1
jdk.internal.le#18.0.1
jdk.internal.opt#18.0.1
jdk.internal.vm.ci#18.0.1
jdk.internal.vm.compiler#18.0.1
jdk.internal.vm.compiler.management#18.0.1
jdk.jartool#18.0.1
jdk.javadoc#18.0.1
jdk.jcmd#18.0.1
jdk.jconsole#18.0.1
jdk.jdeps#18.0.1
jdk.jdi#18.0.1
jdk.jdwp.agent#18.0.1
jdk.jfr#18.0.1
jdk.jlink#18.0.1
jdk.jpackage#18.0.1
jdk.jshell#18.0.1
jdk.jsobject#18.0.1
jdk.jstatd#18.0.1
jdk.localedata#18.0.1
jdk.management#18.0.1
jdk.management.agent#18.0.1
jdk.management.jfr#18.0.1
jdk.naming.dns#18.0.1
jdk.naming.rmi#18.0.1
jdk.net#18.0.1
jdk.nio.mapmode#18.0.1
jdk.random#18.0.1
jdk.sctp#18.0.1
jdk.security.auth#18.0.1
jdk.security.jgss#18.0.1
jdk.unsupported#18.0.1
jdk.unsupported.desktop#18.0.1
jdk.xml.dom#18.0.1
jdk.zipfs#18.0.1
Modules known to the bundled JRE:
DrKodi.app/Contents/PlugIns/jre/Contents/Home/bin/java --list-modules
java.base#18.0.1
java.datatransfer#18.0.1
java.desktop#18.0.1
java.logging#18.0.1
java.prefs#18.0.1
java.scripting#18.0.1
java.xml#18.0.1
jdk.unsupported#18.0.1
The App uses javafx-weaver, so it is basically a Desktop Spring Boot application.
I am trying the new R package rhino from the Appsilon team to build shiny apps.
Running on a Windows10 laptop I installed the dependencies node.js and yarn as described in this tutorial.
Here is the output of rhino::diagnostics() :
Windows 10 x64 build 19042
R version 4.1.0 (2021-05-18)
rhino: 1.0.0
node: v16.15.0
yarn: 1.22.15
Running rhino::build_sass() gives me this error:
yarn run v1.22.15
$ sass --no-source-map --style=compressed root/app/styles/main.scss:root/app/static/css/app.min.css
Error reading root\app\styles\main.scss: no such file or directory.
error Command failed with exit code 66.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error:
! System command 'yarn' exited with status 66.
i If you can't use Node.js and yarn, try using sass: 'r' configuration.
Run `rlang::last_error()` to see where the error occurred.
I am puzzled by the paths in the call to "sass" that start with "root/app". My app is located in my home directory:
"C:/Users/XXX/Documents/workspace/rhino_dummy"
Is it possible that these paths are wrong in the call?
Luckily, the suggested alternative with the deprecated libsass interpreter works for the sass example in the tutorial. It would be nice to have node.js with sass working on Windows10 for future more complex apps.
Edit 1, after Kat's comment
Thanks Kat for the quick feedback. I added sass via yarn add sass and tried again same error:
> rhino::build_sass()
yarn run v1.22.15
warning ..\..\package.json: No license field
$ sass --no-source-map --style=compressed root/app/styles/main.scss:root/app/static/css/app.min.css
Error reading root\app\styles\main.scss: no such file or directory.
error Command failed with exit code 66.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error:
! System command 'yarn' exited with status 66.
i If you can't use Node.js and yarn, try using sass: 'r' configuration.
Run `rlang::last_error()` to see where the error occurred.
The warning is coming from the pckage.json file that was created by calling yarn inside my R project folder. It has only minimal content:
# package.json
{
"dependencies": {
"sass": "^1.51.0"
}
}
Out of curiosity, I tried to compile the javascript example, also failed with very similar error regarding folder paths:
> rhino::build_js()
yarn run v1.22.15
warning ..\..\package.json: No license field
$ webpack
assets by status 0 bytes [cached] 1 asset
ERROR in main
Module not found: Error: Can't resolve 'C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js' in 'C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node'
resolve 'C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js' in 'C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node'
using description file: C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\package.json (relative path: .)
Field 'browser' doesn't contain a valid alias configuration using description file: C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\package.json (relative path: ./root/app/js/index.js)
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js.json doesn't exist
.wasm
Field 'browser' doesn't contain a valid alias configuration
C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js.wasm doesn't exist
as directory
C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root\app\js\index.js doesn't exist
webpack 5.69.0 compiled with 1 error in 162 ms
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Error in `system_yarn()`:
! System command 'yarn' exited with status 1.
Run `rlang::last_error()` to see where the error occurred.
For Node.js functions to work on Windows 10, you'll need to enable Developer Mode on your system as mentioned in our How-to: Use Rhino on Windows article. This is necessary for symbolic links to work on Windows (and the .rhino/node/root file is a symbolic link to the root of the project).
After you do that, delete the .rhino/node directory from your project, or run rhino:::add_node(clean = TRUE) in the root of your project.
Workaround
This answer is only a workaround, if you cannot enable developer mode on windows (see Kamil Zyla's post for more information).
It looks like the folder name "root" in the error messages is a broken variable.
The folder ...\workspace\rhino_dummy\.rhino\node\root does not exist, but the substructures do exit:
app\styles\main.scss
app\js\index.js
...\workspace\rhino_dummy\.rhino\node
Fix step1
I tried my luck and created the folder "root": C:\Users\XXX\Documents\workspace\rhino_dummy\.rhino\node\root
copied rhino_dummy\app\styles\main.scss to rhino_dummy\.rhino\node\root\app\styles\main.scss
copied rhino_dummy\app\js\index.js to rhino_dummy\.rhino\node\root\app\js\index.js
running rhino::build_sass() and rhino::build_js() now worked!
rhino::build_sass()
yarn run v1.22.15
warning ..\..\package.json: No license field
$ sass --no-source-map --style=compressed root/app/styles/main.scss:root/app/static/css/app.min.css
Done in 0.45s.
rhino::build_js()
yarn run v1.22.15
warning ..\..\package.json: No license field
$ webpack
asset app.min.js 470 bytes [compared for emit] [minimized] (name: main)
runtime modules 670 bytes 3 modules
./root/app/js/index.js 113 bytes [built] [code generated]
webpack 5.69.0 compiled successfully in 846 ms
Done in 2.58s.
Fix step2
copy results back to "static" folder, where they are expected by shiny/rhino
copy rhino_dummy\.rhino\node\root\app\static\css\app.min.css to rhino_dummy\app\static\css\app.min.css
copy \rhino_dummy\.rhino\node\root\app\static\js\app.min.js to \rhino_dummy\app\static\js\app.min.js
launch the app via shiny::shinyAppDir(".")
click the button from the tutorial ;-)
Edit1
Checking the github repo of rhino
SASS
definition of build_sass()
calling yarn("build-sass")
definition of build-sass
showing hard-coded root/app/styles/main.scss
JS
definition of build_js()
calling yarn("build-js")
definition of "webpack" build-js also showing hard-coded "root" in file paths
I'm trying to run an application using the command prompt. It's built in Eclipse, using JavaFx. It's a digital diary program that I've been writing for a while and would like to send it to some friends. It is exported with packaged libraries as a runnable jar file.
I'm using the line
java -jar -Djavafx.verbose=true main.jar --module-path /users/home/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml
to run it.
I've traced the errors (through use of -Djavafx.verbose=true) to java.lang.UnsatisfiedLinkError.
One of them is as follows:
WARNING: java.lang.UnsatisfiedLinkError: Invalid URL for class: jar:rsrc:javafx.graphics.jar!/com/sun/glass/utils/NativeLibLoader.class
What's causing this error?
EDIT after moving the --add-modules before main.jar, I get some new errors.
Exception in thread "main" java.lang.ExceptionInInitializerError
...
Caused by: java.lang.IllegalStateException: This operation is permitted on the event thread only; currentThread = main
...
When specifying arguments for the java virtual machine being run with a -jar command, these arguments need to go before the jar file name in the command line.
Do not use this
It will treat the module arguments as program arguments rather than VM arguments:
java -jar -Djavafx.verbose=true main.jar --module-path /users/home/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml
Instead, use this
java --module-path /users/home/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml -Djavafx.verbose=true -jar main.jar
Backstory:
I'm trying to distribute my openJDK11,openJFX application to my friend.
I'm using this tutorial:
https://medium.com/azulsystems/using-jlink-to-build-java-runtimes-for-non-modular-applications-9568c5e70ef4
You can see here that javafx is listed in my dependencies:
You can see here that my module-info is set up as might be required to run the application:
module FractalFriend_m {
requires javafx.base;
requires javafx.controls;
requires javafx.fxml;
requires javafx.graphics;
opens com.potatospy;
}
You can see here that my VM Options are entered correctly:
--module-path=C:\Users\USERNAME\Documents\javafx-sdk-11.0.2\lib --add-modules=javafx.controls,javafx.fxml,javafx.base,javafx.graphics
Running:
jdeps --module-path C:\Users\USERNAME\Documents\javafx-sdk-11.0.2\lib --list-deps FractalFriend_m.jar
Results in:
java.base
javafx.base
javafx.controls
javafx.fxml
javafx.graphics
And finally, I run jlink to hopefully produce something anyone can run:
jlink --no-header-files --no-man-pages --compress=2 --strip-debug --add-modules javafx.controls,javafx.fxml,javafx.base,javafx.graphics --output java-runtime
Which results in:
Error: Module javafx.base not found
JavaFX should be downloaded separately and on calling jlink it should be specified with the -p (--module-path) argument.
jlink --no-header-files --no-man-pages --compress=2 --strip-debug -p <path_java_fx_sdk_lib> --add-modules javafx.controls,javafx.fxml,javafx.base,javafx.graphics --output java-runtime
I'm trying to configure metaspace for SBT
export SBT_OPTS="-XX:+CMSClassUnloadingEnabled -XX:MaxMetaspaceSize=512M -XX:MetaspaceSize=256M -Xms2G -Xmx2G"
but when I run sbt -v, I have the following output :
[process_args] java_version = '1.8.0_11'
# Executing command line:
java
-XX:+CMSClassUnloadingEnabled
-XX:MaxMetaspaceSize=512M
-XX:MetaspaceSize=256M
-Xms2G
-Xmx2G
-Xms1024m
-Xmx1024m
-XX:ReservedCodeCacheSize=128m
-XX:MaxMetaspaceSize=256m
-jar
/usr/local/Cellar/sbt/0.13.7/libexec/sbt-launch.jar
The problem seems that my custom value for MaxMetaspaceSize is overrided with another value, as shown in output above.
SBT version : 0.13.7
Java version : 1.8
OS : OSX
(copy-pasted from a dear coworker who found the solution)
sbt -mem 2048
=>
-Xms2048m
-Xmx2048m
-XX:ReservedCodeCacheSize=256m
-XX:MaxMetaspaceSize=512m
the default metaspace is based on the xmx value specified with the "-mem" option ;-)
When using sbt 0.13.6 or higher you can create a .sbtopts file in your project root with:
-J-XX:MaxMetaspaceSize=512M
It seems that memory options are only correctly handled when they are specified in JAVA_OPTS
setting export JAVA_OPTS="-XX:+CMSClassUnloadingEnabled -XX:MaxMetaspaceSize=512M -XX:MetaspaceSize=256M -Xms2G -Xmx2G"
gives
sbt -v
[process_args] java_version = '1.8.0_40'
# Executing command line:
java
-XX:+CMSClassUnloadingEnabled
-XX:MaxMetaspaceSize=512M
-XX:MetaspaceSize=256M
-Xms2G
-Xmx2G
-jar
/usr/local/Cellar/sbt/0.13.8/libexec/sbt-launch.jar
[info] Loading global plugins from /Users/ant/.sbt/0.13/plugins
[info] Set current project to ant (in build file:/Users/ant/)
>
Not sure if it's a bug or a feature
export SBT_OPTS="-XX:MaxMetaspaceSize=512m -Xms1024m -Xmx1024m"
works for me in sbt 0.13.11:
sbt -v
[process_args] java_version = '1.8.0_91'
# Executing command line:
java
-XX:MaxMetaspaceSize=512m
-Xms1024m
-Xmx1024m
-jar