Java JAR 文件无法在 Mac 上打开
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/908680/
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 not opening on a Mac
提问by
I have been trying to open a JAR file on my Mac with no success. It says the JAR file could not be opened and asks me to look for any error messages in my console. Here are the console messages. I suspect the prob is in the first line itself, but I am not from a software background, so don't know if this is enough for anyone who knows Java to tell what the issue is. I did update my software, so I am assuming I have the latest version of Java although I don't know how to 100% ensure that - the Java.com website just told me to update the overall software on my Mac and said that will take care of Java's latest version also. Please help!
我一直试图在我的 Mac 上打开一个 JAR 文件,但没有成功。它说无法打开 JAR 文件并要求我在控制台中查找任何错误消息。这是控制台消息。我怀疑问题在第一行本身,但我不是软件背景,所以不知道这是否足以让了解 Java 的人知道问题所在。我确实更新了我的软件,所以我假设我有最新版本的 Java,虽然我不知道如何 100% 确保 - Java.com 网站只是告诉我更新我的 Mac 上的整体软件并说这会还要注意 Java 的最新版本。请帮忙!
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] Exception in thread "main"
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] java.lang.UnsupportedClassVersionError: Bad version number in .class file
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] at java.lang.ClassLoader.defineClass1(Native Method)
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] at java.net.URLClassLoader.access0(URLClassLoader.java:56)
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] at java.net.URLClassLoader.run(URLClassLoader.java:195)
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] at java.security.AccessController.doPrivileged(Native Method)
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
5/26/09 7:48:01 AM [0x0-0x72072].com.apple.JarLauncher[1079] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
回答by mipadi
I'm guessing that the JAR requires Java 6; most Macs only have Java 5 installed.
我猜 JAR 需要 Java 6;大多数 Mac 只安装了 Java 5。
回答by paxdiablo
UnsupportedClassVersionError
- there's your culprit. The class file was generated on a later version of the JDK than the JRE you're trying to run it on.
UnsupportedClassVersionError
- 这是你的罪魁祸首。类文件是在比您尝试运行它的 JRE 更高版本的 JDK 上生成的。
回答by Clint
Currently Macs ship with have Java 1.5. Java 1.6 can be downloaded for 64 bit Intel Macs here: http://support.apple.com/downloads/Java_for_Mac_OS_X_10_5_Update_1. From http://support.apple.com/kb/HT1856:
目前 Mac 附带有 Java 1.5。可以在此处为 64 位 Intel Mac 下载 Java 1.6:http: //support.apple.com/downloads/Java_for_Mac_OS_X_10_5_Update_1。从http://support.apple.com/kb/HT1856:
This release does not change the default version of Java. This release is only for Mac OS X 10.5.2 and later, and should not be installed on earlier versions of Mac OS X. This release is for 64-bit, Intel-based Macs only and cannot run on PowerPC-based or 32-bit Intel-based Macs.
此版本不会更改 Java 的默认版本。此版本仅适用于 Mac OS X 10.5.2 及更高版本,不应安装在早期版本的 Mac OS X 上。此版本仅适用于基于 Intel 的 64 位 Mac,不能在基于 PowerPC 或 32-位基于 Intel 的 Mac。
回答by Brian Agnew
The above exception is thrown when a JVM encounters an unsupported class version. This occurs when the JVM encounters a class built for a laterJVM. So you need to upgrade your VM, then change your default Java.
当 JVM 遇到不受支持的类版本时,会抛出上述异常。当 JVM 遇到为以后的JVM构建的类时,就会发生这种情况。所以你需要升级你的虚拟机,然后改变你的默认 Java。
Here's how to change your default:
以下是更改默认设置的方法:
Type 'java preferences' into Spotlight. You'll see the 'Java Preferences' utility. Run that, and you can change the default Java instance to what you require (probably Java 6).
在 Spotlight 中输入“java 首选项”。您将看到“Java 首选项”实用程序。运行它,您可以将默认 Java 实例更改为您需要的(可能是 Java 6)。
EDIT: That utility is in Application/Utilities/Java. Using Spotlight seems an easier way to find it though!
编辑:该实用程序位于 Application/Utilities/Java 中。不过,使用 Spotlight 似乎更容易找到它!
回答by Lim Jie-Khang
Just right click the .jar file and open with archive utility. Simple.
Location of archive utility: /System/Library/CoreServices/Archive\ Utility.app
只需右键单击 .jar 文件并使用存档实用程序打开。简单的。存档实用程序的位置:/System/Library/CoreServices/Archive\ Utility.app
回答by user10050399
Please download Java SE Development Kit 8u241 from Oracle using
请使用以下命令从 Oracle 下载 Java SE Development Kit 8u241
https://www.oracle.com/java/technologies/javase-jdk8-downloads.html
https://www.oracle.com/java/technologies/javase-jdk8-downloads.html
You will need to create an account on Oracle and download will start automatically.
您需要在 Oracle 上创建一个帐户,下载将自动开始。
Select macOS x64 .After download and installing you will be able to open your file
选择 macOS x64 。下载并安装后,您将能够打开您的文件