openmpi + java, could not find or load main class - java

I am recently trying out the java binding of the openmpi library :
I have succesfully compiled the lib with the following configurations:
$/configure --prefix "/home/yuechuan/Application/.openmpi" --enable-mpi-java --with-jdk-dir="/usr/lib/jvm/java-8-oracle/" --with-jdk-header="/usr/lib/jvm/java-8-oracle/include/"
$sudo make install
I am able to compile a simple java program with : $mpijavac src/com/cyc115/pa2/Main.java
currently $echo $CLASSPATH gives /home/yuechuan/Github/parallel_pa2/src/com/cyc115/pa2/
However I am having trouble to get the class file to run. Here are some alternatives I have tried so far:
$java -Djava.library.path=/home/yuechuan/Application/.openmpi/lib/mpi.jar -cp .:/home/yuechuan/Application/.openmpi/lib/mpi.jar Main
which returns Error: Could not find or load main class Main error.
the pure and simple $java Main command returns NoClassDefFoundError
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: mpi/MPIException
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: mpi.MPIException
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
Here's the java file if anyone needs :
package com.cyc115.pa2;
import mpi.MPI;
import mpi.MPIException;
public class Main {
public static void main(String args[]) throws MPIException
{
MPI.Init(args);
int rank = MPI.COMM_WORLD.getRank();
int size = MPI.COMM_WORLD.getSize();
System.out.print("hello world");
MPI.Finalize();
}
}
Any ideas on how I can get the .class to run?

Since the package is :
package com.cyc115.pa2;
You need to put the file Main.java in a sub-directory named com/cyc115/pa2
The java library path should be a path to the directory containing libmpi_java.so rather than the path to mpi.jar.
To compile:
javac -cp /home/yuechuan/Application/.openmpi/lib/mpi.jar com/cyc115/pa2/Main.java
To run:
java -Djava.library.path=/home/yuechuan/Application/.openmpi/lib/ -cp .:/home/yuechuan/Application/.openmpi/lib/mpi.jar com.cyc115.pa2.Main
The following is not the problem, just an FYI:
It should be --with-jdk-headers with an s rather than --with-jdk-header however you do not have to specify it at all if you are already specifying --with-jdk-dir.

Related

Jython How to Use Standalone JAR?

I am trying to use the Jython PythonInterpreter class, but am struggling a bit.
Due to physical limitations, my scenario lacks any sort of project structure. I simply have a Jython JAR file and a Java file.
I am currently compiling my Java code like so:
javac -cp "jython-standalone-2.7.0.jar" test.java
This command does not fail.
When I try to run the compiled Java, I get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/python/util/PythonInterpreter
at test.main(test.java:9)
Caused by: java.lang.ClassNotFoundException: org.python.util.PythonInterpreter
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)
... 1 more
The code looks like so:
import org.python.util.PythonInterpreter;
class test {
public static void main(String[] args) {
PythonInterpreter interpreter = new PythonInterpreter();
}
}
The code is very simple. Should I be importing the Jython classes a different way? Does my method here have any chance of working?
Thanks
How do you run the command?
You will also need to set the CLASSPATH.

Unable to build jar project

I need help with building jar file. I always getting message Error: Could not find or load main class Main when trying to execute jar file.
My MANIFEST.MF here:
Manifest-Version: 1.0
Main-Class: Main
And my Main.java file:
public class Main {
public static final Charset ISO_8859_1 = StandardCharsets.ISO_8859_1;
public static final Charset UTF_8 = StandardCharsets.UTF_8;
public static void main(String[] args) throws IOException, InvalidFormatException {
for (String arg : args) {
System.out.println("Arg " + arg);
}
//Other code removed
}
I really don't know what I am doing wrong when building jar file that it doesn't see Main class.
After I added env variable it start to see main, but now I am getting another crash:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError:
org/apache/poi/openxml4j/exceptions/InvalidFormatException
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.poi.openxml4j.exceptions.InvalidFormatException
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
It looks that java don't see library files in my jar file. If I check jar file with 7zip I can see library files inside of it.

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

JUnit exception in main?

I am trying to run a simple junit test using OS X and terminal. I have placed the Junit jar file inside my java folder. I was able to compile all of the files using:
javac -cp .:"/Library/java/junit.jar" *.java
It compiles just fine, with no errors. However when I try to run the command:
java TestRunner
It gives the error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/runner/JUnitCore
at TestRunner.main(TestRunner.java:7)
Caused by: java.lang.ClassNotFoundException: org.junit.runner.JUnitCore
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)
... 1 more
I cannot seem to find what I am doing incorrectly. Any help solving this would be greatly appreciated.
Like #ToddSewell said, the external libraries should be in your classpath for the execution too. Try this:
java -cp .:"/Library/java/junit.jar" TestRunner

Categories