【发布时间】:2011-01-23 18:14:45
【问题描述】:
我正在关注this tutorial 来构建我的第一个 Java 3D 应用程序。我在我的项目中包含了java3D libraries 和我的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,一切正常。
我的问题是这样的:如果我通过简单的双击运行 jar,什么都不会发生。 dll 出现在 jar 附近,但框架从未出现。
在我的代码中添加一些JOptionPane.showMessageDialog() 以找出问题所在,我意识到执行不会引发异常。它只是在加载 dll 后像循环一样冻结。你能帮我理解为什么它只通过双击 jar 就挂起吗?问题是什么?
【问题讨论】: