How to debug Groovy interpreter in eclipse - java

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.

Related

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

Why exec-maven-plugin fails while java console command works?

This problem has arisen while working with the Java Chromium Embedded Framework (JCEF).
The JCEF uses a native SO library (libcef.so) and a SO library for the JNI bindings (libjcef.so). I believe the embedded Chromium looks for a file named icudtl.dat next to it, i.e. in the same directory that the libraries reside.
For the following explanation, asume that all those required files are in the same directory, named jcef_libs.
I wrote a test application using JCEF. After compiling, if I execute it with the java command, i.e.
$ export LD_LIBRARY_PATH=/path/to/jcef_libs
$ java -cp src/main/java:/path/to/maven/repo/jcef.jar:/path/to/maven/repo/jogl-all/2.2.4/*:/path/to/maven/repo/gluegen-rt/2.2.4/* tests.simple.MainFrame
it works flawlessly.
On the other hand, using the exec-maven-plugin raises a fatal error, due to not finding the named icudtl.dat file. The POM file is configured to use exactly the same artifacts as the java command does.
$ mvn exec:java -Dexec.mainClass="tests.simple.MainFrame"
[1201/123038:FATAL:content_main_runner.cc(721)] Check failed: base::i18n::InitializeICU().
I have tested the java command with the icudtl.dat file removed from the jcef_libs directory, experiencing the same error, i.e. the error raises only when the icudtl.dat is not found.
Any help will be appreciated.
UPDATE
I have been tracing what maven does under the hood. The failing mvn command above executes this internally:
java -classpath /usr/share/maven2/boot/classworlds.jar -Dclassworlds.conf=/usr/share/maven2/bin/m2.conf -Dmaven.home=/usr/share/maven2 org.codehaus.classworlds.Launcher "exec:java" "-Dexec.mainClass=tests.simple.MainFrame"
I.e. it executes my test application through a launcher. I don't know where this launcher is going to execute my application but, again, I need the icudtl.dat in that directory.
Any idea how could I workaround this?

How to run java code from shell script on linux

I want to set a cron job for my java code and I have tried this from project directory
java -classpath .:/home/project/lib/* pkg_name.my_code
and it works fine, however I dont know how to run it from any other directory[like in script]
I have tried to add diroctry (having compiled classes) in classpath like this
java -classpath .:/home/project/lib/*;/home/project/pkg_name/* pkg_name.my_code
also tried
java -classpath ".:/home/project/lib/*;/home/project/pkg_name/*" pkg_name.my_code
but it gives error:
**Error: Could not find or load main class pkg_name.my_code
**
can any please help me ?
If you want to run your project from another directory, then you need to include your project in classpath. So you can do this
java -classpath ".:/home/project/lib/*:/home/project" pkg_name.my_code
For example :
java -classpath ".:/home/test/runjavafromanotherdirectory/lib/*:./runjavafromanotherdirectory" com.test.Main
One of your mistake is you are using ; instead of :.

java.lang.NoSuchMethodError: clojure.lang.KeywordLookupSite when running Leiningen

I have just downloaded Leiningen but I cannot manage to run it. After downloading its own Jar archive, the script fails with a java error. By running bash -x lein I can see that it hangs at this line:
+ exec java -Xbootclasspath/a:/home/andrea/.m2/repository/org/clojure/clojure/1.2.1/clojure-1.2.1.jar -client -Dleiningen.original.pwd=/home/andrea/bin -cp /home/andrea/.clojure/clojure.jar:::::test/:src/:resources/:/home/andrea/.lein/self-installs/leiningen-1.6.2-standalone.jar clojure.main -e '(use '\''leiningen.core)(-main)' /dev/null
Which produces:
Exception in thread "main" java.lang.RuntimeException: java.lang.NoSuchMethodError: clojure.lang.KeywordLookupSite.<init>(ILclojure/lang/Keyword;)V
at clojure.lang.Util.runtimeException(Util.java:165)
at clojure.lang.Compiler.eval(Compiler.java:6476)
at clojure.lang.Compiler.eval(Compiler.java:6431)
at clojure.core$eval.invoke(core.clj:2795)
at clojure.main$eval_opt.invoke(main.clj:296)
Interestingly, what fails is not the Java call, but the snippet '(use '\''leiningen.core)(-main)'. Running that line without it fires in fact a working clojure REPL. The leiningen-1.6.2-standalone.jar seem to be in the right path. Any ideas? I am new to both Java and Clojure...
According the the reference [1], you need to add Clojure home to the classpath.
echo "export CLOJURE_HOME=$HOME/Opt/clojure
export CLASSPATH=$CLASSPATH:$CLOJURE_HOME" >> $HOME/.profile
[1] http://myminutes.wordpress.com/2011/12/01/clojure-lein-gives-error-exception-in-thread-main-java-lang-runtimeexception-java-lang-nosuchmethoderror-clojure-lang-keywordlookupsite/
Chui Tey's answer points in the right direction. If, however, you don't have a stand-alone Clojure installation, but instead solely use Leiningen to bootstrap your projects, you should instead add the Leiningen standalone JAR to the classpath.
Thus:
export CLASSPATH="$CLASSPATH:$HOME/.lein/self-installs/leiningen-VERSION-standalone.jar"

Java and LD_LIBRARY_PATH

I am facing an issue when setting the native library path for a Java process (say, com.example.Main), launched via a simple bash script on a 64-bit CentOS 5 machine.
The related script code is as follows:
#!/bin/bash
export JAVA_HOME=/usr/local/java
export EXTRA_LD_LIBRARY_PATH=/opt/extra/lib64:/opt/extra/java/libs
${JAVA_HOME}/bin/java -Djava.library.path=${EXTRA_LD_LIBRARY_PATH}:${LD_LIBRARY_PATH} com.example.Main
In the EXTRA_LD_LIBRARY_PATH, I have placed some 64-bit native libraries that are needed by the Main class.
However, the Main class causes a Java InternalError to be thrown, despite the library files being in /opt/extra/lib64. If, however, I copy these same library files to /usr/lib64, the error goes away and the code works as expected. (Incidentally, env shows that LD_LIBRARY_PATH is not set, so /usr/lib64 is apparently used by some default setting.)
Is that normal behavior?
Thanks!

Categories