问题描述
我编写了一个应该导出一组Windows注册表项的代码。我已经成功编写了代码,并且能够将执行代码的结果作为jar文件发送到我的电子邮件中。但是,在测试jar文件时(我在java网站的build.xml中包含了一段代码,允许我从 dist 文件夹中运行jar文件)我能够在我的机器上获得所需的结果,因为我在Windows 8.1机器上编写了代码。在另一台机器(使用Windows 8和Windows 7专业版)上进行测试时,我无法执行代码,而我得到的错误如下:
I've written a code that is supposed to be exporting a set of windows registry keys. I've successfully written the code and was able to also send the results of executing the code as a jar file to my email. However, while testing the jar file ( I've included the piece of code in the build.xml from the java website that will allow me to run the jar file out of the dist folder) I was able to get the desired results on my machine because I wrote the code on a windows 8.1 machine. While testing it on another machine ( with Windows 8 and Windows 7 professional ) I was not able to execute the code and the error I was getting was as follows :
Java虚拟机启动程序,发生了Java异常。
当我没有在构建中包含代码时,我曾经收到该错误消息.xml页面允许jar文件用完dist文件夹,但是现在当我在不同于我自己的机器上执行jar文件时我得到它
I used to get that error message when I did not include the code in the build.xml page to allow the jar file to run out of the dist folder, but now I'm getting it when I'm executing the jar file on different machines other than my own
从命令提示符运行它是我得到的:
Running it from the command prompt this is what i got:
Exception in thread "main" java.lang.UnsupportedClassVersionError: smc_1/SMC_1
W1 : Unsupported major.minor version 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
推荐答案
@Sara,该错误是JVM不匹配错误。我想你正在尝试在安装了Java 7(或更旧版本)的系统上运行为Java 8编译的jar。您可以选择(a)将JVM更新为Java 8或(b)将目标设置为1.7或您需要定位的任何JVM重新编译应用程序,前提是您的应用程序不包含任何Java 8特定代码。 Oracle提供了一些有关将Java更新到最新版本的信息:
@Sara, that error is a JVM mismatch error. I think you're trying to run a jar compiled for Java 8 on a system with Java 7 (or older) installed. Your options are (a) update the JVM to Java 8 or (b) recompile your application with the target set to 1.7 or whatever JVM you need to target, provided that your app doesn't include any Java 8-specific code. Oracle has some information on updating Java to the latest version here: http://www.java.com/en/download/help/java_update.xml
这篇关于在其他Windows版本上运行jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!