我最近嘗試了Java的了openmpi庫的結合:的openmpi + java中,找不到或無法加載主類
我已成功編譯的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
我我能夠編譯一個簡單的Java程序有:$mpijavac src/com/cyc115/pa2/Main.java
$echo $CLASSPATH
給/home/yuechuan/Github/parallel_pa2/src/com/cyc115/pa2/
但是,我無法運行類文件。以下是一些備選到目前爲止,我曾嘗試:
$java -Djava.library.path=/home/yuechuan/Application/.openmpi/lib/mpi.jar -cp .:/home/yuechuan/Application/.openmpi/lib/mpi.jar Main
返回Error: Could not find or load main class Main
錯誤。
的單純和簡單$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
這裏的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();
}
}
我如何能得到任何想法的.class運行?
謝謝:)它的工作原理! – cyc115
並注意這正確地具有java.library.path作爲目錄,而不是問題所做的jar文件。 –