为什么我的 Java 桌面应用程序无法运行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6833529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 17:29:26  来源:igfitidea点击:

Why is my Java Desktop Application Failing to Run?

javaswingcompiler-errorsjavafxnetbeans-7

提问by Dorothy

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:

我有一个带有 JavaFX 2 的 Java 桌面应用程序,我构建了它,然后我尝试运行 JAR。运行失败,所以我通过命令行运行它以获取错误。这是我得到的:

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.quantum.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.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.dlland 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.

编辑:Main.java 中的第 150 行是public static JFXPanel javafxPanel = new JFXPanel. 看起来 FX 需要mat.dll并且它在错误的位置寻找它所以它找不到它。我在 Vista(32 位)上运行该程序,但是当我在 Windows 7(64 位)上运行时,第一行(下方)不存在。

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:

经过一些互联网研究,我发现了以下类似的讨论,我仍在研究:

It looks like msvcr100.dlland mat.dllare 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.

看起来msvcr100.dllmat.dll与 JavaFX 运行时有关。我有 JavaFX Netbeans 插件,但没有运行时。我现在有了它,但这并没有解决或改变问题。我在 ....netbeans\7.0\lib\javafx2-win\bin\ 以及 C:\Program Files\Oracle\JavaFX Runtime 2.0\bin 中找到了 msvcr100.dll 和 mat.dll(在我安装了运行时之后)。使用 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.

这不是我第一次运行这个程序。在过去的尝试中,它是成功的。通过 Netbeans 运行不会产生任何错误并且程序运行正常。

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

这可能是外汇错误吗?如何让我的程序显示在正确的位置,为什么不正确?

采纳答案by Dorothy

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.

经过更多研究,我决定复制位于 *....netbeans\7.0\lib\javafx2-win* 和 *C:\Program Files\Oracle\JavaFX Runtime 2.0 中的 bin 文件夹(在我安装运行时) * 到我的 JAR 所在的位置。

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

这有效!我猜JavaFX需要bin文件夹中的DLL。不知道为什么它们不会自动包含在内。

回答by Barry Nirmal

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

我遇到了同样的问题,但这就是我解决它的方法。在 Windows 下,我用以下几行创建了一个批处理文件

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

它运行良好。在 setcalsspath.bat 中,我将 PATH 设置如下

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;

回答by Vishal Rao

I think your PATHis not set to point to required JNI libraries.

我认为您PATH没有设置为指向所需的 JNI 库。

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
  1. 请输入echo %PATH%并报告您所看到的内容。
  2. 在同一个命令提示符下,键入 set PATH=%PATH%;C:\Users\user\Desktop\bin
  3. 在相同的命令提示符下,重复您的原始命令: java -jar DesktopApp.jar

回答by user489041

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

如果我没记错的话,这与 Microsoft Visual C 运行时有关。尝试安装 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.

编辑:尝试将addDllLocationToPath("C:\\WINDOWS\\system32\\msvcr100.dll");第一行代码添加到您的应用程序中。


    /**
     * 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;
    }