问题
Hi guys
I'm following this tutorial to build my first Java 3D application. I included in my project the java3D libraries and my DllLoader class that extracts (from the classpath to the jar's location) and loads the 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();
}
}
Everything works fine if I run the project from Netbeans or if i open the jar from the command line with java -jar Hello3DWorld.jar"
.
My problem is this: if I run the jar with a simple double click nothing happens. The dll appear near the jar but the frame never appear.
Putting some JOptionPane.showMessageDialog()
in my code to find out what's going wrong, I realized that the execution throws no exception.
It just freezes like in a loop after loading the dll.
Can you help me to understand why it hangs only by double clicking the jar and what's the problem?
回答1:
Solved my problem :D
There were an error in the Windows Registry...
this is the solution:
1) run regedit
2) find HKEY_CLASSES_ROOT\jarfile\shell\open\command
3) make sure the path for javaw.exe is correct
回答2:
Does it even run? You could just not have the right file association to run jar files using javaw.
See this StackOverflow question regarding jar file association.
来源:https://stackoverflow.com/questions/4775487/java-3d-hello-world-jar-freeze