[英]why is my jar file not being executable after clean and build project from Netbeans?
I followed some online tutorial and build a little GUI. 我遵循了一些在线教程,并构建了一些GUI。 I tried to make a jar file by clean and build project in the Netbeans, but the jar file doesn't let me open for some reason.
我试图通过清理来创建一个jar文件并在Netbeans中构建项目,但是由于某种原因,该jar文件不允许我打开。 Am i missing other stuff?
我想念其他东西吗?
okay here is what happens after i type in java -jar GUI2.jar
好的,这是我输入
java -jar GUI2.jar
后发生的情况
Exception in thread "main" java.lang.UnsupportedClassVersionError: gui2/GUI2 : U nsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source) 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$000(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) Could not find the main class: gui2.GUI2. Program will exit
If you want to execute a JAR file, you can run from command line "java -jar yourJarFilePathHere". 如果要执行JAR文件,可以从命令行“ java -jar yourJarFilePathHere”运行。
Also, take a look at this SO post... 另外,看看这个SO帖子...
https://stackoverflow.com/a/5258323/1246574 https://stackoverflow.com/a/5258323/1246574
Unsupported major.minor version 51.0
不支持的major.minor版本51.0
This tells that runtime environment doesn't support the format of class compiled 这表明运行时环境不支持已编译类的格式
Either upgrade JRE to supported version or compile your source with runtime environment compatibility by adding -source
switch 要么将JRE升级到受支持的版本,要么通过添加
-source
开关来编译具有运行时环境兼容性的-source
For netbeans: right click on project > properties > source select the source version compatible with your runtime version (java -version from terminal where you are running it) and rebuild the jar 对于netbeans:右键单击项目>属性>源,选择与您的运行时版本兼容的源版本(从运行它的终端的java -version)并重建jar。
The problem is that when you compile a java file it targets a certain version of Java (1.6, 1.7, etc). 问题是,当您编译Java文件时,它针对Java的特定版本(1.6、1.7等)。 So if you compile your project for version 1.7, but on your computer you only have installed 1.6, it will give you this Unsupported major.minor version error when you try to run it.
因此,如果您为1.7版编译项目,但在计算机上仅安装了1.6版,则在尝试运行该项目时会出现此Unsupported major.minor版本错误。 That just means there's a mismatch between the target version and the installed version.
这仅表示目标版本与已安装版本之间不匹配。
The solution: check the Java version currently installed on your computer with java -version from the command line. 解决方案:从命令行使用java -version检查计算机上当前安装的Java版本。 I would just go ahead and update to be safe.
为了安全起见,我会继续进行更新。 Then check the target in your Netbeans settings (right click your project name -> Properties -> Sources -> Source/Binary format)
然后在Netbeans设置中检查目标(右键单击项目名称->属性->源->源/二进制格式)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.