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

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

jar file doesn't run

javajaralert

提问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 .classfile) and a META-INF\MANIFEST.MFfile, which contains information about the jar file. Think of what a .jarfile is to java, as a .dllis 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 classnameis 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

  1. 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.
  2. If the actual OS is a *nix System, verify that the current file attributed allow execution for you.
  3. The jarextension may be associated with a different local application, like an archiving tool. Solving this again is OS dependent.
  1. 并非每个 jar 文件都是可执行的。您可以轻松地在 shell 类型中对其进行测试java -jar /<path-to-jar>/<jar-file-name>.jar,如果没有任何反应(但出现错误),则 java lib 不是应用程序。
  2. 如果实际操作系统是 *nix 系统,请验证当前文件属性是否允许为您执行。
  3. jar扩展可以与不同的本地应用程序相关联,就像一个归档工具。再次解决此问题取决于操作系统。


Here are some steps to test/perform, then it should work:

以下是测试/执行的一些步骤,然后它应该可以工作:

  1. 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.
  2. navigate to the folder that has your jar file (like: C:\jars)
  3. Nowexecute the command java -jar lingpipe-4.1.0.jar
  1. 打开 cmd 并执行java -version- 您应该从 java 可执行文件获得响应。如果没有,请将 JREs bin 文件夹添加到您的 PATH 环境中。
  2. 导航到具有您的jar文件的文件夹(如:C:\jars
  3. 现在执行命令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 存档(但不能从我当前的位置测试/证明它)。这是一个页面,其中包含指向命令外壳示例的链接。我建议您只查看这些页面并按照其说明进行操作。