Error: java.lang.NoClassDefFoundError when running java from NodeJs - java

I'm trying to execute a jar file from nodeJs, I've been using both child_proces.exec and child_process.spawn. with both cases I'm receiving this error:
Error: Exception in thread "main"
Error: java.lang.NoClassDefFoundError: com/ftdi/FTDevice
I'm using ubuntu 14.04 with java, jdk, etc' installed.
Here is my code:
using exec:
var exeprocess = exec('java -Djava.library.path=./ftd2xx.so -jar DenkoviRelayCommandLineTool_10.jar DAE000dY 4 2 1');
using spawn:
var proc = spawn('java',
[ '-jar',
'-Djava.library.path=./ftd2xx.so',
'DenkoviRelayCommandLineTool_10.jar',
'DAE000dY ','4','2','1'
]);
I've figure out that both cases can't locate classes in ft2xx.so, but why?
b.t.w: double check that the command/locations are correct and the exact same script work perfectly in terminal

You will need to add -classpath <path of jar>/JavaFTD2XX-0.2.5.jar to your exec or spawn to avoid NoClassDefFoundError.

Related

ASN1 Compile issue with Bash file in Android

I am trying to generate java files from asn1 file using the below in my android project and facing error in generating the files in Mac OS and in window it worked fine.
org.openmuc:jasn1:1.9.0
org.openmuc:jasn1-compiler:1.9.0
Below is the bash file
#!/bin/bash
JARS_LOCATION="../build/libs-all"
MAIN_CLASS="org.openmuc.jasn1.compiler.Compiler"
SYSPROPS=""
PARAMS=""
SCRIPT_HOME=`dirname $0`
CLASSPATH=$(JARS=("$SCRIPT_HOME"/"$JARS_LOCATION"/*.jar); IFS=:; echo "${JARS[*]}")
for i in $#; do
if [[ $i == -D* ]]; then
SYSPROPS="$SYSPROPS $i";
else
PARAMS="$PARAMS $i";
fi
done
java $SYSPROPS -cp $CLASSPATH $MAIN_CLASS $PARAMS
and the above bash file will be called from my projects build.gradle file.
Below is the final command will be executed from the bash. Shortened the file paths for easy understanding.
java -cp "/libs/antlr-2.7.7.jar:/libs/jasn1-1.9.0.jar:/libs/jasn1-compiler-1.9.0.jar" org.openmuc.jasn1.compiler.Compiler -p com.test.package.asn1 -f /asn1def/asn1/RSPDefinition.asn /asn1def/asn1/PKIX1Explicit88.asn /asn1def/asn1/PKIX1Implicit88.asn -o /asn1def/build/generated/source/java
Below is the error I am getting
Generated code will be saved in /asn1def/build/generated/source/java
Parsing "/asn1def/asn1/RSPDefinition.asn"
Parsing "/asn1def/asn1/PKIX1Explicit88.asn"
Parsing "/asn1def/asn1/PKIX1Implicit88.asn"
Generating classes for module "PKIX1Implicit88"
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
at org.openmuc.jasn1.compiler.HexConverter.toShortHexString(HexConverter.java:63)
at org.openmuc.jasn1.compiler.HexConverter.toShortHexString(HexConverter.java:59)
at org.openmuc.jasn1.compiler.HexConverter.appendShortHexString(HexConverter.java:99)
at org.openmuc.jasn1.compiler.HexConverter.appendHexString(HexConverter.java:108)
at org.openmuc.jasn1.compiler.HexConverter.toHexString(HexConverter.java:9)
at org.openmuc.jasn1.compiler.BerClassWriter.writeEncodeTag(BerClassWriter.java:2169)
at org.openmuc.jasn1.compiler.BerClassWriter.writeSequenceOrSetEncodeFunction(BerClassWriter.java:1107)
at org.openmuc.jasn1.compiler.BerClassWriter.writeSequenceOrSetClass(BerClassWriter.java:731)
at org.openmuc.jasn1.compiler.BerClassWriter.writeConstructedTypeClass(BerClassWriter.java:493)
at org.openmuc.jasn1.compiler.BerClassWriter.translateModule(BerClassWriter.java:194)
at org.openmuc.jasn1.compiler.BerClassWriter.translate(BerClassWriter.java:133)
at org.openmuc.jasn1.compiler.Compiler.main(Compiler.java:89)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 12 more
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':asn1def:compileAsn'.
> Process 'command '/asn1def/run-scripts/jasn1-compiler'' finished with non-zero exit value 1
I have the main class in the jasn1-compiler-1.9.0.jar file in the libs folder. The same generate files in windows but in Mac it is not working. The difference in windows & Mac is Java version. Mac has Java 11 & windows has Java 1.8. I also tried adding the JDK 1.8 location as below at the end of above code.
-Dorg.gradle.java.home=/Users/Shared/Jenkins/.jenkins/tools/hudson.model.JDK/JDK_1_8
Can anyone help me to point out what's missing?
Finally I found the answer. The error was happened because of the Java version in Mac, it has Java 11 and it didn't support javax xml bind. So I installed the JDK 1.8 in the mac machine and use that path in the bash file as below before the java execution line in bash file.
export JAVA_HOME=/usr/java/jdk1.8.161/
It may useful for someone.

Java: Class not found for PageRank algorithm in Apache Hadoop

I am trying to run PageRank algorithm in Apache Hadoop (2.6.5) cluster (1 master 2 slaves). I am using the program in this repository - https://github.com/danielepantaleone/hadoop-pagerank.git. I was able to compile all the sources using this command -
sudo javac -classpath ${HADOOP_CLASSPATH} -d ./build src/it/uniroma1/hadoop/pagerank/PageRank.java src/it/uniroma1/hadoop/pagerank/job1/PageRankJob1Mapper.java src/it/uniroma1/hadoop/pagerank/job1/PageRankJob1Reducer.java src/it/uniroma1/hadoop/pagerank/job2/PageRankJob2Mapper.java src/it/uniroma1/hadoop/pagerank/job2/PageRankJob2Reducer.java src/it/uniroma1/hadoop/pagerank/job3/PageRankJob3Mapper.java
I created the jar file using this command sudo jar -cf build/pagerank.jar build/.
I am trying to run the program just like the wordcount example like this -
sudo bin/hadoop jar hadoop-pagerank/build/pagerank.jar PageRank --
input /usr/local/hdfs/web-Google.txt --output /usr/local/hdfs-out-PR
Sometimes I get an error like this -
Exception in thread "main" java.lang.NoClassDefFoundError: PageRank (wrong name: it/uniroma1/hadoop
/pagerank/PageRank)
and sometimes I get an error like this - Exception in thread "main" java.lang.ClassNotFoundException: PageRank for different types of compilation.
I am not sure what am I doing wrong. Can anyone please help me in proper steps to compile and run the program in Hadoop ? I dont have any pom.xml file and I am able to run the provided wordcount example jar.
You have to use package name before the name of the class,
it means you have to use :
it.uniroma1.hadoop.pagerank.PageRank
rather than PageRank
in your command.
like this :
hadoop jar hadoop-pagerank/build/pagerank.jar it.uniroma1.hadoop.pagerank.PageRank --input /usr/local/hdfs/web-Google.txt --output /usr/local/hdfs-out-PR

java System.loadLibrary() load failed in mac, but System.load() works fine

I code a JNI demo in mac, I found java System.loadLibrary() load failed in mac, but System.load() works fine.I have tried some way to solve this problem, but didn't work, can someone give me advice.there are ways I have tried:
1、set "-Djava.library.path=/Users/wang/javaPrj/AndroidPushServer/out/production" in IDEA "debug-Configurations-VM Options",the running log as follow: /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/bin/java -Djava.library.path=/Users/wang/javaPrj/AndroidPushServer/out/production -Didea.launcher.port=7532 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA CE.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home/jre/lib/charsets.jar ... /Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain com.yuwan.androidpushserver.server
/Users/wang/javaPrj/AndroidPushServer/out/production
Exception in thread "main" java.lang.UnsatisfiedLinkError: no push in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
...
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:123)
Process finished with exit code 1
the libpush.so is exists in that directory:
lxr:production wang$ pwd
/Users/wang/javaPrj/AndroidPushServer/out/production
lxr:production wang$
lxr:production wang$ ls
AndroidPushServer libpush.so
lxr:production wang$
2、I run java in command "java -Djava.library.path=/Users/wang/javaPrj/AndroidPushServer/out/production com/yuwan/androidpushserver/server", the error as follow:
lxr:AndroidPushServer wang$ java -Djava.library.path=/Users/wang/javaPrj/AndroidPushServer/out/production com/yuwan/androidpushserver/server
/Users/wang/javaPrj/AndroidPushServer/out/production
Exception in thread "main" java.lang.UnsatisfiedLinkError: no push in java.library.path
...
at com.yuwan.androidpushserver.server.(server.java:13)
lxr:AndroidPushServer wang$
3、I set java.library.path in java code by call System.setProperty("java.library.path", "/Users/wang/javaPrj/AndroidPushServer/out/production"), but still load fail.
Take a look here for a sample code that uses JNI and IDEA:
http://jnicookbook.owsiak.org/recipe-No-D002/
You can find super simple source code here as well:
http://jnicookbook.owsiak.org/recipe-No-001/
And you can take a look at the movie that shows how to deal with JNI debugging within IntelliJ and CLion here:
https://www.youtube.com/channel/UCE2aYTLqPQ8Qx8oTkOjjwSQ
If you do System.loadLibrary("push") in mac os X it will load libpush.dylib not libpush.so. If you do System.load you can load any file name you want.

Javauto Compile fails (Getting started)

Following Getting started -
(Windows 7, console: C:...>, .jar & .javauto in the same folder)
java -jar javauto.jar => OK, help is displayed
javauto hello.javauto => command not recognised
javauto.jar hello.javauto => NO result
So i tried this
java -jar javauto.jar -v hello.javauto
Giving this exception (NB: c:...>javac => help display is OK)
Generating ←[92mhello←[0m...
Getting user imports... None
Getting user global variables... None
Getting user functions... None
Generating functions... ←[93mmouseMove ←[0m←[93mmsgBox ←[0m←[93mprint ←[0m←[93msleep ←[0m
Generating class variables... ←[93msimulatedMotionSpeed ←[0m
Generating imports... ←[93mAWTException ←[0m←[93mMouseInfo ←[0m←[93mRobot ←[0m←[93mJDialog ←[0m←[93
mJOptionPane ←[0m
Generating struct objects... None
Generation complete... starting build
Executing cmd /c attrib +s +h "C:\Users\Francis\Develop\java\Javauto\.hello"...
Building ←[92mC:\Users\Francis\Develop\java\Javauto\.hello\class\hello.class←[0m...
Exception in thread "main" java.lang.NullPointerException: Couldn't find java system compiler.
at com.automation.javauto.compiler.CustomJavaCompiler.compile(CustomJavaCompiler.java:36)
at com.automation.javauto.parser.Create.main(Create.java:419)
Try this:
1) Compile it using this command:
java -jar javauto.jar hello.javauto
2) Now that you have compiled your program, there will be a file called hello.jar. Execute with:
java -jar hello.jar

Executing a Ruby script from Java using JRuby results in 'LoadError: no such file to load ...'

I'd like to execute a Ruby script from Java using JRuby (Linux Mint). I can successfully execute the script from the terminal by calling ruby script.rb. However, the script contains a require that causes "no such file to load" exception when trying to execute it from Java using JRuby:
package com.company;
import org.jruby.embed.LocalVariableBehavior;
import org.jruby.embed.PathType;
import org.jruby.embed.ScriptingContainer;
public class Main
{
public static void main(String[] args)
{
ScriptingContainer ruby;
ruby = new ScriptingContainer(LocalVariableBehavior.PERSISTENT);
Object result = ruby.runScriptlet(PathType.ABSOLUTE, "/home/user/Scripts/script.rb");
}
}
The problem seems to be in the require ... part of the script.rb, since this code works fine for e.g. a simple script that only displays text.
The script uses WinRb, a Ruby library for Windows Remote Management. script.rb:
require 'winrm'
endpoint = 'http://somehost.domain.org:5985/wsman'
krb5_realm = 'DOMAIN.ORG'
command = 'hostname'
winrm = WinRM::WinRMWebService.new(endpoint, :kerberos, :realm => krb5_realm)
winrm.cmd(command) do |stdout, stderr|
STDOUT.print stdout
STDERR.print stderr
end
When I run the Java code I get this exception:
LoadError: no such file to load -- winrm
require at org/jruby/RubyKernel.java:940
<top> at /home/user/Scripts/script.rb:5
Exception in thread "main" org.jruby.embed.EvalFailedException:
(LoadError) no such file to load -- winrm
Here's what I tried:
adding require 'rubygems' to the top of the script. This only changes the exception to LoadError: no such file to load -- rubygems
specifying full path: require '/var/lib/gems/1.9.1/gems/winrm-1.3.3/lib/winrm'. Instead of the original exception, at runtime I now get: LoadError: no such file to load -- date
require at org/jruby/RubyKernel.java:940
Other:
$ ruby -v
ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]
$ jruby -v
jruby 9.0.0.0 (2.2.2) 2015-07-21 e10ec96 Java HotSpot(TM) 64-Bit Server VM 25.45-b02
How can I get JRuby to execute this script successfully?
The solution is:
jruby -S gem install winrm

Categories

Resources