java jar 文件不运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6611245/
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
jar file doesn't run
提问by Matt
I'm fairly new to Java and having recently installed the latest JDK I'm having trouble getting files with a .jar extension to run. When I double-click them I simply get an alert noise and nothing more. I have tried jarfix.exe, tried changing the associated program in folder options and even reinstalling Java. Not sure what else to do. Any help greatly appreciated thanks!
我对 Java 还很陌生,最近安装了最新的 JDK 我在运行 .jar 扩展名的文件时遇到了问题。当我双击它们时,我只会听到警报声,仅此而已。我尝试过 jarfix.exe,尝试更改文件夹选项中的关联程序,甚至重新安装 Java。不知道还能做什么。任何帮助非常感谢谢谢!
回答by Tank
Within your jar/zip file go to the INF\MANIFEST.MF file, there should be a line that looks like
在您的 jar/zip 文件中转到 INF\MANIFEST.MF 文件,应该有一行看起来像
Main-Class: ClassName
if there is not one, try adding it.
如果没有,请尝试添加它。
回答by Ed Staub
Try running from the command line and see what error messages you get.
尝试从命令行运行并查看您收到什么错误消息。
java -jar your.jar
回答by Buhake Sindi
A java jar file is a library file containing compiled java files (with a .class
file) and a META-INF\MANIFEST.MF
file, which contains information about the jar file. Think of what a .jar
file is to java, as a .dll
is to Windows.
java jar 文件是一个库文件,包含编译后的java 文件(带有一个.class
文件)和一个META-INF\MANIFEST.MF
文件,其中包含有关jar 文件的信息。想想.jar
文件对于 Java 的意义,就像文件.dll
对于 Windows 的意义一样。
To run your jar file, you need to install java and, on command-line, type:
要运行您的 jar 文件,您需要安装 java 并在命令行中键入:
java -cp myJar.jar classname
where classname
is a fully qualified java class name (e.g. com.neurologic.main.MyProgram
).
哪里classname
是完全限定的java 类名(例如com.neurologic.main.MyProgram
)。
Here(or here) is more information on how to bundle your application (that contains public static void main(String[] args)
method) into your JAR file.
此处(或此处)是有关如何将您的应用程序(包含public static void main(String[] args)
方法)捆绑到 JAR 文件中的更多信息。
回答by Andreas Dolk
- Not every jar file is executable. You can test it easily, in a shell type
java -jar /<path-to-jar>/<jar-file-name>.jar
, if nothing happens (but an error), the java lib is not an application. - If the actual OS is a *nix System, verify that the current file attributed allow execution for you.
- The
jar
extension may be associated with a different local application, like an archiving tool. Solving this again is OS dependent.
- 并非每个 jar 文件都是可执行的。您可以轻松地在 shell 类型中对其进行测试
java -jar /<path-to-jar>/<jar-file-name>.jar
,如果没有任何反应(但出现错误),则 java lib 不是应用程序。 - 如果实际操作系统是 *nix 系统,请验证当前文件属性是否允许为您执行。
- 该
jar
扩展可以与不同的本地应用程序相关联,就像一个归档工具。再次解决此问题取决于操作系统。
Here are some steps to test/perform, then it should work:
以下是测试/执行的一些步骤,然后它应该可以工作:
- open cmd and execute
java -version
- you shouldget a response from the java executable. If not, add the JREs bin folder to your PATH environment. - navigate to the folder that has your jar file (like:
C:\jars
) - Nowexecute the command
java -jar lingpipe-4.1.0.jar
- 打开 cmd 并执行
java -version
- 您应该从 java 可执行文件获得响应。如果没有,请将 JREs bin 文件夹添加到您的 PATH 环境中。 - 导航到具有您的jar文件的文件夹(如:
C:\jars
) - 现在执行命令
java -jar lingpipe-4.1.0.jar
Personally I doubtthat the lingpipe library is an executablejava archive (but can't test/prove it from my current place). Here is a page that includes a link to command shell examples. I suggest you just look at those pages and follow their instructions.
我个人怀疑lingpipe 库是一个可执行的java 存档(但不能从我当前的位置测试/证明它)。这是一个页面,其中包含指向命令外壳示例的链接。我建议您只查看这些页面并按照其说明进行操作。