Compiled JAVA project, can't make it work - java

got a problem, can't manage it to work for me right.
Completed my java project and i want it to compile and run for a test. I do compile it as "Jar file" (not runnable jar file). I compile it through Eclipse IDE.
I do not setup any more references in compiling settings, making everything stock. Once i compile it as "Server.jar" in my desktop i'm trying to run through console, because it's more like console program. I'm using macOS.
Using command : java -jar Server.jar
Error:
Ervinass-MacBook-Air:Desktop Ervinas$ java -jar Server.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/simple/parser/ParseException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.json.simple.parser.ParseException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
What should i do?
It shouws class is not found if i'm right?
This : org/json/simple/parser/ParseException is not recognised.
What i have tried : java -classpath ~/Documents/Java/Server/src/server/json-simple.jar -jar Server.jar
As all of you see, i'm using json-simple.jar library, moreover i do use mysql library, so i guess later it will be the same problem with mysql library.
Any solution? Tired of getting it working now..

Related

JNI error: Exception in thread "main" java.lang.NoClassDefFoundError

Error log:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/text/StrSubstitutor
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.text.StrSubstitutor
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
... 7 more
I know that people have asked this question before but none of them are using the Dropwizard framework.
Here is what I have tried:
Different versions of Dropwizard using the pom.xml,
Adding commons-lang and commons-text don't seem to fix it, though commons-text makes it throw a different error,
Restarting my computer.
It is a pretty involved pom.xml file which I am not comfortable sharing...
Any ideas why this is happening?
Is it possible, that you compile with a newer version (like Java 8) and run it with an older version (Java 7)? If yes, check the Path. (1)
Another thing could be, that the apache libraries are compiled with a more recent version.
(1) Try comparing the output of java --version and javac --version

Java cannot find javax/vecmath/Vector3d.class, even with jar in classpath

My platform has ubuntu 18.04.3 and openjdk version "1.8.0_242".
I'm running someone's executable jar file which references javax.vecmath.Vector3d, but the the openjdk vm generates NoClassDefFoundError for that class, as displayed below. The javax class is installed on my system in /usr/share/java/vecmath.jar, I've verified that it contains javax.vecmath.Vector3d, so I provide that jar in the '-cp' option:
% java -cp /usr/share/java/vecmath.jar -jar cameraCalc.jar
But I get this error:
java -cp /usr/share/java/vecmath-1.5.2.jar -jar cameraCalc.jar
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: [Ljavax/vecmath/Vector3d;
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: javax.vecmath.Vector3d
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
... 7 more
Why can't the jvm find that class even though it's in the vecmath.jar provided as a '-cp' option?
Thanks
Tom
My problem was due to running an executable jar file that does not contain all needed classes. From the documentation:
When you use this option, the JAR file is the source of all user
classes, and other user class path settings are ignored.
So "-cp" options will be ignored when running an executable jar file.

How to use Jlex and Cup tools

i'm trying to learn something about JFlex and Cup tools on Ubuntu, because i have to use them for a school project. So i downloaded and installed JFlex and Cup. There are some examples in "jflex-1.6.1/examples", so i tried to run one of them. In particularly i tried to run the one in "jflex-1.6.1/examples/cup", following the instructions in the README file:
To compile:
jflex lcalc.flex
java java_cup.Main < ycalc.cup
javac Main.java
To run:
java Main test.txt
Files:
"Main.java" demo of a main program
"Makefile " makefile to compile and test the example
"README"
"lcalc.flex" the lexer spec
"output.good " how the output should look like for the test
"ycalc.cup" the parser spec
"test.txt " sample input for testing
With many difficulties, i have been finally able to compile, then to complete successfully the first three instructions. Now i have errors when i try to run: java Main test.txt. In particular i get this error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: java_cup/runtime/Scanner
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: java_cup.runtime.Scanner
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
I don't have any idea on how to solve this. I tried also with other examples but the results were the same.
I hope that you can help me. Thank you!
I also got this error, and it's because I forgot to include java-cup.jar and java-cup-runtime.jar in my class path.
Try compiling like this:
javac -cp path/to/java-cup.jar Main.java
And then run your program like this:
java -cp path/to/java-cup-runtime.jar Main

JNI error has occurred when running java with OpenCV from terminal

I'm trying to compile a java-program written with OpenCV 3.2.0 from the terminal. It was originally written in Eclipse with OpenCV as a user library.
I compile it with this command:
javac -cp /opencv-3.2.0-java/build/bin/ *.java
It works with no error, the -cp command shows the path to the OpenCV jar. I then try to run everything with this command:
java -Djava.library.path="/opencv-3.2.0-java/build/lib" -cp jar/opencv-320.jar -classpath . Main
It gives me this error:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: org/opencv/core/Mat
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: org.opencv.core.Mat
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
I searched for solutions to this problem and came to the conclusion that it had something to do with native libraries. I use the -Djava parameter to link to the path of the library files from OpenCV, but it still doesn't work somehow. How do I fix this?
EDIT:
All the .java files are on a folder on the desktop. This is were the Main file is included. For example:
home/pi/Desktop/MultiSensor_v2.0_Java/Main.java
The path to the OpenCV jar:
/home/pi/Desktop/MultiSensor_v2.0_Java/opencv-3.2.0-java/build/bin/opencv-320.jar
The path to OpenCV native libraries:
/home/pi/Desktop/MultiSensor_v2.0_Java/opencv-3.2.0-java/build/lib
-cp is short for -classpath. So I suspect that when you use both, the second one overwrites the first.
You can have multiple entries on the class path separated by : as stated in the documentation: Setting the class path. (actually, it looks like that is a typo in the doc, and it should be ; as a separator. You could try both)
If you execute your command from the directory home/pi/Desktop/MultiSensor_v2.0_Java/ that would make:
java -Djava.library.path="opencv-3.2.0-java/build/lib" -cp .:opencv-3.2.0-java/build/bin/opencv-320.jarr Main

Execute Maven/TestNG project using command line and DIFFERENT xml from command line?

I have written a number of selenium tests using Maven and TestNG that are intended to be ran overnight via Jenkins. However, it has been requested that I write some more specific tests that the QA team can run independently from Jenkins, with specific parameters (sku, etc). Currently my automation tests are ran with maven, but how can I run them from the command line using the testing command, so it will run only run a specific file with command line options? I tried this:
java -cp "/Users/kroe761/.m2/repository/org/testng/testng/6.8/testng-6.8.jar" org.testng.TestNG testng2.xml
But I got this error (which I don't understand at all)
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: com.beust.jcommander.ParameterException
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more
If there is a way to do this with mvn test then that would be even better, but I don't want to have modify the Jenkins job too much.
You can provide suiteXmlFiles params case you're running your tests using surefire plugin, like described in here
When running from command line it should look like this:
mvn test -Dsurefire.suiteXmlFiles=suite_location/suite.xml

Categories