Run Groovy at the CLI with Java 9+ module settings - java

OS: Linux Mint 18.3
The combo I want to run is: Groovy 3.0.+ (app and testing code) & Java 11+ & JavaFX 11+
Having had a little help (see comments here) I can now do this using a gradle.build file (including outputting an executable using the Gradle "installDist" task from the application plugin).
I've also managed to do this from a non-Gradle Groovy-enabled project in IntelliJ, by configuring the classpath and module-path appropriately.
My file javaFXTest.groovy looks like this (NB this is the Groovy script which I get IntelliJ to run):
package core
import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene.Parent
import javafx.scene.Scene
import javafx.stage.Stage
Application.launch( GrApp, args)
class GrApp extends Application {
#Override
void start(Stage primaryStage) {
Parent root = FXMLLoader.load(getClass().getResource("/dialog1.fxml"))
primaryStage.title = "Hello World"
primaryStage.scene = new Scene(root, 1200, 800)
primaryStage.show()
}
}
I'm just wondering, for the sake of interest, how this is actually done in terms of a CLI groovy command. I thought it might be something like this:
groovy -cp .:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/* --module-path /home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib --add-modules javafx.controls,javafx.fxml core/javaFXTest.groovy
oops:
Caught: java.io.FileNotFoundException: /home/mike/IdeaProjects/JavaFXExp2/AppTest/src/main/groovy/--module-path (/home/mike/IdeaProjects/JavaFXExp2/AppTest/src/main/groovy/--module-path)
... it clearly doesn't recognise --module-path as a configurable option, confirmed by going groovy --help. I searched on this and found nothing. And yet IntelliJ manages to run this script: the --module-path and --add-modules options are added as VM options to the run configuration. Anyone know how this might be done as a CLI command?

On the suggestion by cfrick I found the answer: Intellij does indeed show the whole command in the "Run" view (if you click the '...'):
Turns out this is a giant Java command with all sorts of stuff beyond my understanding, and inclusion of many Groovy .jars for example. I show it in its magnificence for anyone interested: I've split up into lines to show the options a bit more clearly.
/usr/lib/jvm/java-1.11.0-openjdk-amd64/bin/java
-Dgroovy.home=/home/mike/.sdkman/candidates/groovy/3.0.2
-Dgroovy.starter.conf=/home/mike/.sdkman/candidates/groovy/3.0.2/conf/groovy-starter.conf
-javaagent:/home/mike/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/201.6073.9/lib/idea_rt.jar=41350:/home/mike/.local/share/JetBrains/Toolbox/apps/IDEA-C/ch-0/201.6073.9/bin
-Dfile.encoding=UTF-8
-classpath /home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-3.0.2.jar org.codehaus.groovy.tools.GroovyStarter
--conf /home/mike/.sdkman/candidates/groovy/3.0.2/conf/groovy-starter.conf
--main groovy.ui.GroovyMain
--classpath .:/home/mike/IdeaProjects/JavaFXExp2/out/production/AppTest:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-test-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-yaml-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-platform-launcher-1.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-jupiter-api-5.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-jupiter-engine-5.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-templates-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-groovysh-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jsp-api-2.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ant-1.10.7.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jackson-dataformat-yaml-2.10.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/javaparser-core-3.15.13.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-json-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ant-launcher-1.10.7.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-xml-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-testng-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-jmx-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/commons-logging-1.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-dateutil-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-4.13.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/hamcrest-core-1.3.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/xstream-1.4.11.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ivy-2.5.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-servlet-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/gpars-1.2.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jcommander-1.72.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jsr166y-1.7.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ant-antlr-1.10.7.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/multiverse-core-0.7.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-jsr223-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-sql-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-groovydoc-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/bsf-2.4.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/org.abego.treelayout.core-1.0.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jackson-core-2.10.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ST4-4.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-console-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jackson-annotations-2.10.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jansi-1.18.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-datetime-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-astbuilder-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-jaxb-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-ant-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-test-junit5-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-swing-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/qdox-1.12.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-cli-picocli-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/javax.servlet-api-3.0.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-cli-commons-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-macro-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-nio-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-platform-engine-1.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/junit-platform-commons-1.6.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/testng-6.14.3.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jackson-databind-2.10.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/ant-junit-1.10.7.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/opentest4j-1.2.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-bsf-3.0.2.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/commons-cli-1.4.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/snakeyaml-1.24.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/jline-2.14.6.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/groovy-docgenerator-3.0.2.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/src.zip:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx-swt.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.web.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.base.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.fxml.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.media.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.swing.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.controls.jar:/home/mike/.java/JavaFX/javafx-sdk-11.0.2/lib/javafx.graphics.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/extras-jaxb/jaxb-api-2.3.0.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/extras-jaxb/activation-1.1.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/extras-jaxb/jaxb-core-2.3.0.1.jar:/home/mike/.sdkman/candidates/groovy/3.0.2/lib/extras-jaxb/jaxb-impl-2.3.0.1.jar
--encoding=UTF-8
/home/mike/IdeaProjects/JavaFXExp2/AppTest/src/main/groovy/core/javaFXTest.groovy
I hazard a guess that the first -classpath option (with the single dash) is presumably setting that for the "javaagent"... or could it be for the "Groovy starter"...?
This at least solves the conundrum: I had understood that Groovy (even Groovy 3) can't handle Java 9+ modules. So it would make sense that this must be a Java command. Maybe running with a groovy commmand will become possible with Groovy 4, which as I understand it will (hopefully) be able to be able to handle these modules.

Related

Java program uses wrong locale when jpackaged

I am parsing strings representing German-style numbers (i.e., decimal comma and optional full stop for grouping thousands), e.g., "2.804,13"; this is just done using a DecimalFormat based on my desired Locale:
package loc_test;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Locale;
public class ParseNumbers {
static final DecimalFormat df = (DecimalFormat) NumberFormat.getNumberInstance(Locale.GERMANY);
public static void main(String[] args) throws Exception {
for (String s : new String[] { "2.815,53", "2815,53" }) {
System.out.println(String.format("%s \t-> %s", s, df.parse(s)));
}
}
}
This gives the desired output, e.g., when compiled and run from the command line:
2.815,53 -> 2815.53
2815,53 -> 2815.53
However, when I bundle it as a jpackage image (./gradlew jpackageImage using Gradle and the Badass Runtime Plugin) and run the resulting binary, the output seems to indicate that a wrong locale is used:
2.815,53 -> 2.815
2815,53 -> 281553
I have tried out a few things (in vain), and the problem does not seem to be in the code itself:
Added Locale.setDefault(Locale.GERMANY) in the main. Locale.getDefault() will show the German locale, but it has no effect.
Explicitly set -Duser.country=DE and -Duser.language=de via Java command line parameters. System.getProperty(...) shows the expected values, but again, no effect. (Also, from the command line, it also works with these being set to the system defaults.)
Added -Djava.locale.providers=COMPAT,CLDR,SPI to the jpackage Java command line parameters (from this thread). Again, I can verify from the main that the property is set correctly, but it makes no difference. (And seems to have been an issue with earlier Java versions anyway.)
I have seen the problem first using Java 16 with Gradle 7.2; and it has persisted after an update to Java 17 and Gradle 7.3. The problem has occurred both on an English Linux system and a German Windows machine.
Using --info with the jpackageImage command, Gradle shows me which JDK it is using:
Starting process 'command '.../.gradle/jdks/jdk-17+35/bin/jpackage''. Working directory: .../LocTest/app Command: .../.gradle/jdks/jdk-17+35/bin/jpackage --type app-image --input .../LocTest/app/build/install/app/lib --main-jar app.jar --main-class LocTest.App --dest .../LocTest/app/build/jpackage --name app --runtime-image .../LocTest/app/build/jre --java-options -Duser.country=DE --java-options -Duser.language=de --java-options -Djava.locale.providers=COMPAT,CLDR,SPI
When I use that .gradle/jdks/jdk-17+35/bin/java to run the class, i.e., run:
~/.gradle/jdks/jdk-17+35/bin/java -cp app/build/classes/java/main loc_test.App`
With this, the problem does not occur; the numbers are correct.
However, the problem does occur when I use the (supposedly same) JRE bundled with the jpackage image, i.e., I get the wrong numbers using:
./app/build/jpackage/app/lib/runtime/bin/java -cp app/build/classes/java/main/ loc_test.App
Why would the java, when packaged, ignore the locale?
Am I missing something here, or might this be a bug in jpackage or the plugin, or in the Java release itself?
The whole Gradle example project (very small) can be found at Github.
Check what modules are included in your runtime image.
For example when I run java --list-modules on JDK 17 I notice this module:
jdk.localedata
I don't know if it is required for this, but I bet that module isn't being included by jpackage unless it is specifically requested.
Run ./app/build/jpackage/app/lib/runtime/bin/java --list-modules and compare with ~/.gradle/jdks/jdk-17+35/bin/java --list-modules to confirm. Then consider making an image with jlink that includes jdk.localedata if it was missing to test this hypothesis.

JavaFX 11: "JavaFX runtime components are missing"

I'm trying to run sample JavaFX code (taken from the 5th edition of Java Illuminated) under JavaFX 11 and Java 11, using jGRASP 2 under Windows 10.
I've read through the "Getting Started with JavaFX" guide (https://openjfx.io/openjfx-docs/) extensively, and while I've made some progress, I'm stuck.
I've downloaded the latest ZIP file, unpacked it, and updated the CLASSPATH to include a path to the jar files needed to compile. I can successfully compile the file. However, when I try to run, I get the following error message:
Error: JavaFX runtime components are missing, and are required to run this application
The "Getting Started" guide says that this can be fixed by adding the following options to the runtime call:
--module-path "[path]\lib" --add-modules=javafx.controls,javafx.fxml
I've added the options, but I'm still getting the error message.
Previous StackOverflow articles usually end with the option setting above; alas, I can't figure out what else to do.
As a first time user, I've managed to make it work, but it was not straightforward to me.
I guess there are no many people familiarized with this IDE, so I'm going to post the steps I followed, as a basic tutorial:
Download and install jGRASP version 2.0.5_05 Beta.
Since I have a few JDKs installed, it selected by default JDK 10.0.2, so my first step was to find a way to work with JDK 11. That can be done in Settings -> jGrasp Startup Settings, where I can set the path for my java executable:
Then I restarted jGrasp. You can verify which JDK the IDE is using in Tools -> System Info -> Java Version.
Open HelloFX sample class. I've started with the most basic sample from the OpenJFX docs. The code can be found here.
Build -> compile, as expected, will throw a bunch of errors given that JavaFX is no longer part of the JDK:
Following the OpenJFX docs, we need to download the JavaFX SDK from here, and then add the library to the classpath. Go to Settings -> PATH/CLASSPATH -> Workspace, press New, and add, one by one, the different JavaFX jars from the downloaded SDK/lib folder (at least javafx-base.jar, javafx-graphics.jar and javafx-controls.jar).
Build -> compile should work now.
Next step: Build -> Run. This fails:
----jGRASP exec: java HelloFX
Error: JavaFX runtime components are missing, and are required to run this application
----jGRASP wedge: exit code for process is 1.
----jGRASP: operation complete.
That was expected. According to the docs, we need to set the module-path and add-modules arguments.
First attempt: use Run arguments. After setting:
--module-path /Users/<user>/Downloads/javafx-sdk-11.0.2/lib --add-modules javafx.controls
running again failed with the exact same error message as above, but with one difference in the console log:
----jGRASP exec: java HelloFX --module-path /Users/<user>/Downloads/javafx-sdk-11.0.2/lib --add-modules javafx.controls
What's wrong with that!? Well... if you try that on command line, it will fail as well, because the order of arguments is wrong, the vm arguments should go before the class name.
In conclusion: Run arguments are not VM arguments!
Second attempt: In order to provide the VM arguments, the option I found was to edit Settings -> Compiler settings -> Workspace. By default, it is using jdk (integrated debugger) - generic. You can view it and see that for Run it uses:
java %S -ea %S %<FLAGS2> %<MAIN_CLASS> %<ARGS>
So instead of ARGS we need to find a way to set FLAGS2.
Luckily, next to the Environment tab, there is a Flags/Args tab, and there we can set our vm arguments in FLAGS2:
--module-path /Users/<user>/Downloads/javafx-sdk-11.0.2/lib --add-modules javafx.controls
Apply, close the dialog, and Build -> Run the class, now it will work!
If you see the console log, it contains exactly the command you would use when running on command line:
----jGRASP exec: java --module-path /Users/<user>/Downloads/javafx-sdk-11.0.2/lib --add-modules javafx.controls HelloFX
----jGRASP: operation complete.
I guess the next step will be running a more complex project...
Try simply creating a launcher with only a main Method. It could look something like this:
package application;
import javafx.application.Application;
public class MyAppLauncher {
public static void main(final String[] args) {
Application.launch(MyApp.class, args);
}
}
(you can leave the old main Method unused in your App for the time-being)
This worked for me with JDK 13 & JavaFX 13 & Eclipse 2019-12 under Ubuntu.
(I created the Project using "new/Maven Project/Simple Project" and then just added JavaFX, Logging & other stuff as dependencies in pom.xml, which all landed on the Classpath. Only the JDK was on the Modulepath)
No need to bother about Java Modules.
If that works, you can take time to learn about Java Modularisation another day...
...and remember to vote for this Answer. :-)

Issue running tensorflow with java

I am having some issues running tensorflow with java. I am using CUDA 8 with CuDNN 6.
I tried following the quickstart instructions located here: https://www.tensorflow.org/install/install_java and get the following error message when I attempt to run the example java program:
java -cp libtensorflow-1.4.0.jar:. -Djava.library.path=./jni HelloTF
Exception in thread "main" java.lang.UnsatisfiedLinkError: Cannot find TensorFlow native library for OS: linux, architecture: x86_64. See https://github.com/tensorflow/tensorflow/tree/master/tensorflow/java/README.md for possible solutions (such as building the library from source). Additional information on attempts to find the native library can be obtained by adding org.tensorflow.NativeLibrary.DEBUG=1 to the system properties of the JVM.
at org.tensorflow.NativeLibrary.load(NativeLibrary.java:75)
at org.tensorflow.TensorFlow.init(TensorFlow.java:66)
at org.tensorflow.TensorFlow.<clinit>(TensorFlow.java:70)
at org.tensorflow.Graph.<clinit>(Graph.java:258)
at HelloTF.main(HelloTF.java:8)
The jni directory contains the following:
libtensorflow_framework.so
libtensorflow_jni.so
LICENSE
I then tried installing the binaries from source as suggested here:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/java/README.md
This is the output from setting: org.tensorflow.NativeLibrary.DEBUG=1
org.tensorflow.NativeLibrary: tryLoadLibraryFailed: /path/to/jni/libtensorflow_jni.so: libcublas.so.8.0: cannot open shared object file: No such file or directory
org.tensorflow.NativeLibrary: jniResourceName: org/tensorflow/native/linux-x86_64/libtensorflow_jni.so
org.tensorflow.NativeLibrary: frameworkResourceName: org/tensorflow/native/linux-x86_64/libtensorflow_framework.so
But I still get the same error message when I try and run the example Java program.
What am I doing wrong??
Any help would be greatly appreciated!
The error
Cannot find TensorFlow native library for OS: linux, architecture: x86_64.
is clearly stating that the library is not visible to your software.
To make it available to the Java class, try doing like that (in the same shell obviously):
export LD_LIBRARY_PATH=/the/absolute/path/to/your/library
java -cp libtensorflow-1.4.0.jar:. -Djava.library.path=./jni HelloTF
also ensure you're running the java command from the same directory which contains the /jni directory.
For those landing here and facing the same issue.
You are probably trying to run your program from eclipse. Then, you have to go to Run configurations > Arguments and pass this arguments:
Program arguments -> models/
images/example-400x288.jpg
VM Arguments -> -Djava.library.path=./jni
like in this screenshot:
When people (like myself) come from python to java world, everything is strange! here is how I solved my problem regarding all linking errors:
I assumed you already have simple hello Tensorflow project, explained here
Download and copy tensorflow JNI files to :/usr/lib/tensorflow
Download and copy desired version of tensorflow Lib jar file to: /usr/lib/tensorflow
Compile with java
Compile java file
javac -cp /usr/lib/tensorflow/libtensorflow-1.14.0.jar HelloTensorFlow.java
run java file:
java -cp /usr/lib/tensorflow/libtensorflow-1.14.0.jar:. -Djava.library.path=/usr/lib/tensorflow/ HelloTensorFlow
use MAVEN
First we should export LD_LIBRARY_PATH:
export LD_LIBRARY_PATH=/usr/lib/tensorflow
Then run maven build command:
mvn -q compile exec:java
I hope it helps you

How to debug Groovy interpreter in eclipse

Groovy interpreter is built atop JVM. I made some Java libraries for JVM and some functions in the library will be called when running groovy scripts. Unfortunately, some error happens.
Therefore, I tried to launch groovy interpreter in the eclipse, so that I can set breakpoints in my code and debug the issue.
Therefore, what I have done is:
First, I run the script in linux using groovy --indy ackermann.groovy 2 and then using ps to show the detail parameters. What I got is something like:
/homes/sxu3/298182/bin/java -Xbootclasspath/p:/homes/sxu3/tools/jars/asmInliner-4.0.1.jar:/homes/sxu3/tools/jars/invoke.jar:/homes/sxu3/tools/jars/asm-all-5.0.3.jar:/homes/sxu3/tools/jars/common-4.0.1.jar:/homes/sxu3/tools/jars/logback-classic-1.1.3.jar:/homes/sxu3/tools/jars/logback-core-1.1.3.jar:/homes/sxu3/tools/jars/slf4j-api-1.7.7.jar:/homes/sxu3/tools/jars/conf/ -classpath /homes/sxu3/bin/groovy-2.4.8/lib/groovy-2.4.8.jar -Dscript.name=/homes/sxu3/bin/groovy-2.4.8/bin/groovy -Dprogram.name=groovy -Dgroovy.starter.conf=/homes/sxu3/bin/groovy-2.4.8/conf/groovy-starter.conf -Dgroovy.home=/homes/sxu3/bin/groovy-2.4.8 -Dtools.jar=/homes/sxu3/298182/lib/tools.jar org.codehaus.groovy.tools.GroovyStarter --main groovy.ui.GroovyMain --conf /homes/sxu3/bin/groovy-2.4.8/conf/groovy-starter.conf --classpath . --indy ackermann.groovy 2
In eclipse, I create a run configuration > Java application > new.
The main class is:
org.codehaus.groovy.tools.GroovyStarter
and the VM Arguments:
-Dscript.name=Y:\bin\groovy-2.4.8\bin\groovy -Dprogram.name=groovy -Dgroovy.starter.conf=Y:\bin\groovy-2.4.8\conf\groovy-starter.conf -Dgroovy.home=y:\bin\groovy-2.4.8 -Dtools.jar=Y:\298182\lib\tools.jar --main groovy.ui.GroovyMain --conf Y:\bin\groovy-2.4.8\conf\groovy-starter.conf -classpath . --indy
and the "Program Arguments":
Y:\bin\indy-benchmark-suite_orig\programs\groovy\ackermann.groovy 300
This is shown as in the
3 Add my libraries to the VM bootstrap and classpath.
After clicking the Run in the debug configuration, I got errors below:
JVMJ9VM007E Command-line option unrecognised: --main
The trick is at groovy's groovy.sh script, which launches a Java process. Therefore, I am looking whether some people can help solve it. Also how interpreter developers debug during development.

Get eclipse (java) to work with java3d

I have a simple java project (adapted from the example here), which is as follows:
import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.geometry.ColorCube;
import javax.media.j3d.BranchGroup;
public class HelloWorld {
public HelloWorld()
{
SimpleUniverse universe = new SimpleUniverse();
BranchGroup group = new BranchGroup();
group.addChild(new ColorCube(0.3));
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(group);
}
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println("PATH : " + System.getProperty("java.library.path"));
new HelloWorld();
}
}
My output is:
Hello World!
PATH : /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/server:/usr/lib/jvm/java-6-openjdk/jre/lib/amd64:/usr/lib/jvm/java-6-openjdk/jre/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib
Exception in thread "main" java.lang.UnsatisfiedLinkError: no j3dcore-ogl in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at javax.media.j3d.NativePipeline$1.run(NativePipeline.java:231)
at java.security.AccessController.doPrivileged(Native Method)
at javax.media.j3d.NativePipeline.loadLibrary(NativePipeline.java:200)
at javax.media.j3d.NativePipeline.loadLibraries(NativePipeline.java:157)
at javax.media.j3d.MasterControl.loadLibraries(MasterControl.java:987)
at javax.media.j3d.VirtualUniverse.<clinit>(VirtualUniverse.java:299)
at HelloWorld.<init>(HelloWorld.java:10)
at HelloWorld.main(HelloWorld.java:20)
I assume this Exception indicates that the library libj3dcore-ogl.so could not be found. Here's where it is located:
$ locate libj3dcore-ogl.so
/usr/lib/jni/libj3dcore-ogl.so
As the output above shows, /usr/lib/jni is inside java.library.path. What am I doing wrong? (I'm using Ubuntu 10.04 and Eclipse 3.7.2 - if that may be an issue?)
Java is a bit of unknown territory for me. So please be as verbose as possible on your notes/suggestions/answers.
Update 1
Apparantly it's a 64-bit library (on a 64-bit operating system):
$ file /usr/lib/jni/libj3dcore-ogl.so
/usr/lib/jni/libj3dcore-ogl.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, stripped
I use openjdk as runtime environment. Both java3d (libjava3d-java) and the openjdk (openjdk-6-jdk) is installed via aptitude.
Interestingly, it works if I compile and run the application from my terminal:
javac -classpath /usr/share/java/j3dcore.jar:/usr/share/java/j3dutils.jar:/usr/share/java/vecmath-1.5.2.jar:. HelloWorld.java
java -classpath /usr/share/java/j3dcore.jar:/usr/share/java/j3dutils.jar:/usr/share/java/vecmath-1.5.2.jar:. HelloWorld
But I would really like to use eclipse to do this kind of things.
$ java -version
java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.13) (6b20-1.9.13-0ubuntu1~10.04.1)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)
It also works with Eclipse, if I copy the native library (libj3dcore-ogl.so) to the jvm directory and add the libraries (j3dcore.jar, j3dutils.jar, vecmath-1.5.2.jar) as external jars to the build path libraries (right click on project -> Properties -> Java Build Path -> Libraries -> Add External JARs...):
sudo cp /usr/lib/jni/libj3dcore-ogl.so /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/
But I wonder if there really is no solution that wouldn't require this copy.
I went through similar issues while trying to run a foreign project requiring java3d. I'm using Eclipse only for the compilation and packaging runnable jar parts (as it is a Maven project), but the runtime errors I was getting were of the same kind. And I want to confirm that moooeeeep's answer was pertinent and very helpful. The reason why I'm posting here is mainly because I think this can be useful for other people to give the full steps (independently from Eclipse, since setting up things using Eclipse facilities or Maven dependency ones failed, in both cases). Everything here is all about setting up correctly the JRE.
Note: I'm working under OpenJDK-7-amd64 (and Debian - 64 bit system). So feel free to adapt the following steps for i386 if applicable (just replace "amd64" by "i386").
Here's what worked for me then :
sudo apt-get install libjava3d-jni libjava3d-java libvecmath-java
This will add required files to be injected in the JRE:
$ locate j3d
/usr/lib/jni/libj3dcore-ogl.so
/usr/share/java/j3dcore-1.5.2+dfsg.jar
/usr/share/java/j3dcore.jar
/usr/share/java/j3dutils-1.5.2+dfsg.jar
/usr/share/java/j3dutils.jar
Since those files are located in different places but definitely not in the JRE's ones, copy (or link) as follows:
Dynamic libraries :
sudo cp /usr/lib/jni/libj3dcore-ogl.so /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/
JARs :
sudo cp /usr/share/java/j3d*.jar /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/
sudo cp /usr/share/java/vecmath-*.jar /usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/
Resulting in :
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/libj3dcore-ogl.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/j3dcore-1.5.2+dfsg.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/j3dcore.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/j3dutils-1.5.2+dfsg.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/j3dutils.jar
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/ext/vecmath-1.5.2.jar
Hope this can be of any help...
I had the same issue on anothe project, this solved it for me:
Open the run configuration of your project, select the "Arguments" tab and insert the following into the "VM arguments" box
-Djava.library.path=/usr/lib/jni
I don't know why you have to give the path here again. It also doesn't work with relative ones, but this way it works for me.
java.lang.UnsatisfiedLinkError is thrown only if the definition of a native method can't be found.

Categories