[英]openmpi + java, could not find or load main class
I am recently trying out the java binding of the openmpi library : 我最近正在尝试openmpi库的java绑定:
I have succesfully compiled the lib with the following configurations: 我已经使用以下配置成功编译了lib:
$/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
我可以使用以下命令编译一个简单的Java程序:
$mpijavac src/com/cyc115/pa2/Main.java
currently $echo $CLASSPATH
gives /home/yuechuan/Github/parallel_pa2/src/com/cyc115/pa2/
当前
$echo $CLASSPATH
给出/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. 返回
Error: Could not find or load main class Main
错误。
the pure and simple $java Main
command returns NoClassDefFoundError
简单的
$java Main
命令返回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 : 如果有人需要,这是java文件:
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? 关于如何使.class运行的任何想法?
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. 您需要将文件Main.java放在名为
com/cyc115/pa2
的子目录中libmpi_java.so
库路径应该是包含libmpi_java.so
的目录的路径,而不是libmpi_java.so
的路径。
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
. 它应该是
--with-jdk-headers
和s,而不是--with-jdk-header
但是如果您已经指定了--with-jdk-dir
则不必完全指定它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.