开发者

Why is my Java Desktop Application Failing to Run?

I have a Java Desktop Application with JavaFX 2 which I built and then I tried to run the JAR. The run failed so I ran it through the Command Line to get the errors. Here is what I got:

Edit: I updated the stack trace as some lines of code have been added/removed (The error is the same)

C:\Users\user\Desktop>java -jar DesktopApp.jar
Error: failed to msvcr100.dll java.lang.UnsatisfiedLinkError: Can't load library: C:\Users\user\Desktop\bin\msvcr100.dll
*** Fallback to Prism SW pipeline
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: java.lang.UnsatisfiedLinkError: Can't load library: C:\Users\user\Desktop\bin\mat.dll
        at com.sun.javafx.tk.quantu开发者_Go百科m.QuantumToolkit.startup(QuantumToolkit.java:252)
        at com.sun.javafx.application.PlatformImpl.startup(PlatformImpl.java:30)
        at javafx.embed.swing.JFXPanel.initFx(JFXPanel.java:128)
        at javafx.embed.swing.JFXPanel.<init>(JFXPanel.java:138)
        at app.Main.<clinit>(Main.java:150)
Caused by: java.lang.UnsatisfiedLinkError: Can't load library: C:\Users\user\Desktop\bin\mat.dll
        at java.lang.ClassLoader.loadLibrary(Unknown Source)
        at java.lang.Runtime.load0(Unknown Source)
        at java.lang.System.load(Unknown Source)
        at com.sun.glass.utils.NativeLibLoader.loadLibraryFullPath(NativeLibLoader.java:155)
        at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:85)
        at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:30)
        at com.sun.glass.ui.Application$1.run(Application.java:27)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.glass.ui.Application.loadNativeLibrary(Application.java:25)
        at com.sun.glass.ui.win.WinApplication.<clinit>(WinApplication.java:33)
        at com.sun.glass.ui.win.WinPlatformFactory.createApplication(WinPlatformFactory.java:20)
        at com.sun.glass.ui.win.WinPlatformFactory.createApplication(WinPlatformFactory.java:17)
        at com.sun.glass.ui.Application.Run(Application.java:49)
        at com.sun.javafx.tk.quantum.QuantumToolkit.startup(QuantumToolkit.java:242)
        ... 4 more
Could not find the main class: app.Main. Program will exit.

Edit: Line 150 in Main.java is public static JFXPanel javafxPanel = new JFXPanel. It appears that FX is requiring mat.dll and it is looking in the wrong place for it so it can't find it. I am running the program on a Vista (32bit) but when I run on Windows 7 (64bit) the first line (below) is not there.

Error: failed to msvcr100.dll java.lang.UnsatisfiedLinkError: Can't load library: C:\Users\user\Desktop\bin\msvcr100.dll

After More Research:

After some internet research I found the below similar discussions which I am still studying:

  • http://forums.oracle.com/forums/thread.jspa?threadID=2230876&tstart=31
  • http://forums.oracle.com/forums/thread.jspa?threadID=2250369
  • http://netbeans.org/bugzilla/show_bug.cgi?id=198599

It looks like msvcr100.dll and mat.dll are related to the JavaFX Runtime. I have the JavaFX Netbeans Plugin but I did not have the runtime. I now have it but that did not fix or change the problem. I found msvcr100.dll and mat.dll in ....netbeans\7.0\lib\javafx2-win\bin\ and also (after I installed the runtime) in C:\Program Files\Oracle\JavaFX Runtime 2.0\bin. It appears that my program is looking in the right place when run with Netbeans.


This is not the first time I ran this program. In past tries it was successful. Running through Netbeans does not produce any errors and the program runs properly.

Could this be an FX bug? How do I get my program to look in the right place and why is it not?


After even more research I decided to copy the bin folder located in *....netbeans\7.0\lib\javafx2-win* and also (after I installed the runtime) in *C:\Program Files\Oracle\JavaFX Runtime 2.0* to where my JAR is located.

This Worked! I guess the DLLs in the bin folder are required for JavaFX. Not sure why they would not automatically be included.


I had the same problem but this is how I solved it. Under Windows, I created a batch file with the following lines

call c:\bkn-batfiles\setclasspath.bat 
set
java -jar  E:\DATA\JAVACLASSES-NETBEANS\search_files_with_java_fx\dist\search_files.jar 
pause 

It runs great. In setcalsspath.bat I set the PATH as follows

SET PATH=.;C:\bkn-batfiles;
SET PATH=%PATH%c:\Program Files\java\jdk1.7.0_03\bin;
SET PATH=%PATH%c:\Program Files\java\jdk1.7.0_03\lib;
SET PATH=%PATH%C:\Program Files\Oracle\JavaFX 2.0 SDK\rt\bin;


I think your PATH is not set to point to required JNI libraries.

Follow these instructions:

  1. Please type echo %PATH% and report back on what you see.
  2. At the same command prompt, type set PATH=%PATH%;C:\Users\user\Desktop\bin
  3. At the same command prompt, repeat your original command: java -jar DesktopApp.jar


If i'm not mistaken, that is related the Microsoft Visual C Runtime. Try installing the Microsoft Visual C++ 2010 Redistributable Package (x86)

However, a more interesting question to ask is why is you application trying to use this and why is it looking on your desktop for it?

EDIT: Try adding addDllLocationToPath("C:\\WINDOWS\\system32\\msvcr100.dll"); as the first line of code to your application.


    /**
     * Allows you to add a path to the library path during runtime
     * @param dllLocation The path you would like to add
     * @return True if the operation completed successfully, false otherwise
     */
    public static boolean addDllLocationToPath(final String dllLocation)
    {
        //our return value
        boolean retVal = false;
        try
        {
            System.setProperty("java.library.path", System.getProperty("java.library.path") + ";" + dllLocation);
            //get the sys path field
            Field fieldSysPath = ClassLoader.class.getDeclaredField("sys_paths");
            fieldSysPath.setAccessible(true);
            fieldSysPath.set(null, null);
            retVal = true;
        }
        catch (Exception e)
        {
            System.err.println("Could not modify path");
        }
        return retVal;
    }

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜