程序在 Eclipse 中运行,但导出的可运行 jar 文件打不开?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27915510/
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-09-19 22:20:11  来源:igfitidea点击:

Program runs in Eclipse, but exported runnable jar file will not open?

javaeclipsefilejarrunnable

提问by Dan

It looks like this is a common problem, but none of the previous posts seem to address my issue.

看起来这是一个常见问题,但以前的帖子似乎都没有解决我的问题。

I believe I've narrowed it down to one problem. Any application that uses an InputStream will not open, but all my other applications run fine.

我相信我已经将其缩小为一个问题。任何使用 InputStream 的应用程序都不会打开,但我所有的其他应用程序都运行良好。

The application runs fine in Eclipse, but the window won't even open when I try to run the jar file.

该应用程序在 Eclipse 中运行良好,但当我尝试运行 jar 文件时,该窗口甚至无法打开。

Task manager shows it pop up for about a second or two, and then disappears.

任务管理器显示它弹出大约一两秒钟,然后消失。

I have tried all three options for the Library handling upon exporting and none of them fix the issue.

我在导出时尝试了库处理的所有三个选项,但都没有解决问题。

Can anyone explain this?

谁能解释一下?

回答by Konstantin Komissarchik

Run it from the command line. This will allow you to see the exception that's thrown that's preventing your program from progressing.

从命令行运行它。这将允许您查看引发的阻止您的程序进行的异常。

java -jar YourJar.jar

回答by Phily N.

I know I'm late, but I want to prevent people having to search hours for the same Error I just did. In Eclipse the path-String isn't case-sensitive. In the exported Runnable Jar File it is. So make sure all the pathsnames have the capital letters in the right positions, or to be save don't have capital letters at all.

我知道我迟到了,但我想防止人们不得不为我刚刚做的同样的错误搜索几个小时。在 Eclipse 中,路径字符串不区分大小写。在导出的 Runnable Jar 文件中。因此,请确保所有路径名在正确的位置都有大写字母,或者根本没有大写字母。

回答by Isaiah van der Elst

Setup Your Manifest

设置您的清单

If I had to guess, your manifest doesn't contain your main class OR the classpath is not defined.

如果我不得不猜测,您的清单不包含您的主类或未定义类路径。

Main-Class: https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
Class-Path: https://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

主类https: //docs.oracle.com/javase/tutorial/deployment/jar/appman.html
类路径https: //docs.oracle.com/javase/tutorial/deployment/jar/downman.html

If you're using a build tool like maven, it needs to be configured to add these properties: https://maven.apache.org/shared/maven-archiver/examples/classpath.html

如果您使用的是像 maven 这样的构建工具,则需要对其进行配置以添加这些属性:https: //maven.apache.org/shared/maven-archiver/examples/classpath.html

Execute Your Jar

执行你的 Jar

There are two ways to run an executable jar. As an executable jar you need to define the Main-Class and Class-Path in your manifest:

有两种方法可以运行可执行的 jar。作为可执行 jar,您需要在清单中定义 Main-Class 和 Class-Path:

java -jar YourJar.jar


You can also skip setting up your manifest and define your classpath and main class through the JVM's parameters.


您还可以跳过设置清单并通过 JVM 的参数定义类路径和主类。

java -cp=${PATH_TO_JAR} main.package.MainClass