我正在按照本教程构建我的第一个 Java 3D 应用程序。我在我的项目中包含了java3D 库和我的DllLoader类,它们提取(从类路径到 jar 的位置)并加载j3dcore-ogl.dll
:
public class DllLoader {
private DllLoader() {
}
public static void extractAndLoad(String dll) throws IOException {
int aux = dll.lastIndexOf('/');
if (aux == -1) {
aux = dll.lastIndexOf('\\');
}
File dllCopy = new File((aux == -1) ? dll : dll.substring(aux + 1));
try {
System.load(dllCopy.getAbsolutePath());
} catch (UnsatisfiedLinkError e1) {
try {
DllLoader.copyFile(DllLoader.class.getResourceAsStream(dll), dllCopy);
System.load(dllCopy.getAbsolutePath());
} catch (IOException e2) {
}
}
}
private static void copyFile(InputStream pIn, File pOut) throws IOException {
if (!pOut.exists()) {
pOut.createNewFile();
}
DataInputStream dis = new DataInputStream(pIn);
FileOutputStream fos = new FileOutputStream(pOut);
byte[] bytes = new byte[1024];
int len;
while ((len = dis.read(bytes)) > 0) {
fos.write(bytes, 0, len);
}
dis.close();
fos.close();
}
}
如果我从 Netbeans 运行项目,或者如果我从命令行使用java -jar Hello3DWorld.jar"
.
我的问题是这样的:如果我通过简单的双击运行 jar,什么也不会发生。dll 出现在罐子附近,但框架从未出现。
在我的代码中放入一些JOptionPane.showMessageDialog()
内容以找出问题所在,我意识到执行不会引发异常。它只是在加载 dll 后像循环一样冻结。你能帮我理解为什么它只通过双击罐子就挂起吗?问题是什么?