java 如何在 Windows 7 中打开 JAR 文件

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

How to Open JAR Files in Windows 7

javafilewindows-7jarexecutable

提问by Confiqure

I have looked this up on Google and nothing seems to suit my needs. I am using a Windows 7 computer. I have tried to re-install Java 7 and both the JRE and the JDK downloads say that I already have it on my computer.

我在谷歌上查过这个,似乎没有什么适合我的需要。我使用的是 Windows 7 计算机。我尝试重新安装 Java 7,但 JRE 和 JDK 下载都说我已经在我的计算机上安装了它。

I currently have these Java folders:

我目前有这些 Java 文件夹:

  • C:\Program Files\Java\jdk1.6.0_25\
  • C:\Program Files\Java\jdk1.7.0_05\
  • C:\Program Files\Java\jre6\
  • C:\Program Files (x86)\Java\jre7\
  • C:\Program Files\Java\jdk1.6.0_25\
  • C:\Program Files\Java\jdk1.7.0_05\
  • C:\Program Files\Java\jre6\
  • C:\Program Files (x86)\Java\jre7\

My questions:

我的问题:

  1. Which folders are obsolete and can be deleted?

  2. How do I make it so that when I double-click on a .JAR executable file, it will properly open without me having to use a command to open it. When I try to open a JAR file currently, it opens a CMD screen and then closes right after.

  1. 哪些文件夹已过时且可以删除?

  2. 我如何做到这一点,以便当我双击一个 .JAR 可执行文件时,它会正确打开,而不必使用命令来打开它。当我当前尝试打开 JAR 文件时,它会打开一个 CMD 屏幕,然后立即关闭。

回答by Kumar Vivek Mitra

1.If all the Java folders mentioned above by you are having the specified Jdk folder, then its better go for C:\Program Files\Java\jdk1.7.0_05

1.如果你上面提到的所有Java文件夹都有指定的Jdk文件夹,那么最好去C:\Program Files\Java\jdk1.7.0_05

2.Now copy C:\Program Files\Java\jdk1.7.0_05\bininto you System PATH.

2.现在复制C:\Program Files\Java\jdk1.7.0_05\bin到你System PATH

3.Type java -versionon your command prompt, if it returns the Installed version of JAVAon your system, then you have properly configured the Java path.

3.键入java -version您的命令提示符下,如果返回了Java虚拟机版本在系统上,那么你已经正确配置了Java路径。

4.Now if your JARfile is a command line program, then you need to open it from Command Prompt

4.现在如果你的JAR文件是命令行程序,那么你需要从命令提示符打开它

5.But if you have GUI program inside the JAR file, then you can use the below to create a JAR file in Eclipse, and then you can Double-Click on it to execute it.

5.但是如果你的JAR文件中GUI程序,那么你可以使用下面的在Eclipse中创建一个JAR文件,然后你可以双击它来执行它。

File -> Export-> Java ->Runnbale JAR file

Launch configuration : your Class containing the public static void main(String[] args)

Export destination : Target place

Library Handling:

Package required libraries into generated JAR

FINISH

回答by Arun

  • Please check your JAVA_HOME and CLASSPATH settings in your system's environment variables

  • set your JAVA_HOME or CLASSPATH variables accordingly

    If you want to open up a jar file and see its contents, you can use the option "open with" in windows and open that with winzip

  • If you want to execute your jar file while clicking it, then you must have a main-method in your jar file and configure the same in your mainfest file. you should have an Main-Classattribute (sample entry in mainfest file below)

    Main-Class: com.example.MainClass

    Class-Path: lib/lib1.jar lib/lib2.jar

  • 请检查您系统环境变量中的 JAVA_HOME 和 CLASSPATH 设置

  • 相应地设置您的 JAVA_HOME 或 CLASSPATH 变量

    如果要打开 jar 文件并查看其内容,可以在 windows 中使用“打开方式”选项并使用 winzip 打开它

  • 如果您想在单击时执行 jar 文件,那么您的 jar 文件中必须有一个 main-method 并在您的 mainfest 文件中配置相同的方法。你应该有一个Main-Class属性(下面 mainfest 文件中的示例条目)

    主类:com.example.MainClass

    类路径:lib/lib1.jar lib/lib2.jar

回答by Sarel Botha

Check what the .jar extension is associated with. Try running the same command from a command prompt window. Hopefully then you can see what the error is and fix it.

检查 .jar 扩展名与什么相关联。尝试从命令提示符窗口运行相同的命令。希望你能看到错误是什么并修复它。

Uninstalling all java environments and then reinstalling just what you need will probably work. After uninstalling also delete the java*.exe files from c:\windows\system32. You should not need the JAVA_HOME environment variable to be set, but some batch files require it to be set.

卸载所有 Java 环境,然后重新安装您需要的环境可能会奏效。卸载后还要从 c:\windows\system32 中删除 java*.exe 文件。您应该不需要设置 JAVA_HOME 环境变量,但某些批处理文件需要设置它。

If you want Java to work in your browser you must install a 32-bit JRE.

如果您希望 Java 在您的浏览器中运行,您必须安装 32 位 JRE。

If you need to run a java program that uses a huge amount of memory (2GB+) or must call a 64 bit DLL directly using JNI or JNA then you must install a 64 bit JRE. If you do java development then you should install a a JDK instead of the JRE. Your IDE may also require that you install a 64 bit JDK instead of a 32 bit JDK.

如果您需要运行使用大量内存 (2GB+) 的 Java 程序或必须使用 JNI 或 JNA 直接调用 64 位 DLL,那么您必须安装 64 位 JRE。如果你做java开发,那么你应该安装aa JDK而不是JRE。您的 IDE 可能还要求您安装 64 位 JDK 而不是 32 位 JDK。