简体   繁体   English

Windows 10 改java版本?

[英]Windows 10 change java version?

Im working with Intellij IDEA + JDK 14 and want to execute my project as jar in my console.我正在使用Intellij IDEA + JDK 14 ,并希望在我的控制台中以 jar 的形式执行我的项目。 Herefor I use为此我用

java -jar pathToJar

There is always the following Error message:始终有以下错误消息:

Exception in thread "main" java.lang.UnsupportedClassVersionError: de/marco/api/Main has been compiled by a more recent version of the Java Runtime (class file version 58.0), this version of the Java Runtime only recognizes class file versions up to 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)

I know what this error message means, but I dont know how to fix.我知道此错误消息的含义,但我不知道如何修复。 I´ve set already in my system under "PATH" the path to my JDK.我已经在我的系统中的“PATH”下设置了我的 JDK 的路径。 My computer uses Java 8 :我的电脑使用Java 8

C:\Users\User>java -version
java version "1.8.0_261"
Java(TM) SE Runtime Environment (build 1.8.0_261-b12)
Java HotSpot(TM) Client VM (build 25.261-b12, mixed mode)

Could anyone help me how to change the Java version of my Computer, that i could use a newer version for my compiler.任何人都可以帮助我如何更改我的计算机的 Java 版本,以便我可以为我的编译器使用更新版本。 Thanks a lot非常感谢

It is very simple:这很简单:

  • either you tell IntelliJ to compile your classes to java 8 bytecode要么你告诉 IntelliJ 将你的类编译为 java 8 字节码
  • or you ensure that your windows command line is pointing to your java 11 setup或者您确保您的 windows 命令行指向您的 java 11 设置

For Intellij;对于 Intellij; you look into "Project Settings", then turn to "SDKs" under Platform Settings.您查看“项目设置”,然后转到平台设置下的“SDK”。 You could point that to a JDK8 installation.您可以将其指向 JDK8 安装。

Alternatively, as you probably installed Java 14 on purpose: locate where it sits on your disk, and ensure your Windows PATH variable points to that location.或者,由于您可能故意安装了 Java 14:找到它在磁盘上的位置,并确保您的 Windows PATH 变量指向该位置。 Or just put some "wrapper" script somewhere into your PATH, and have that wrapper script call the "java 14" java.或者只是将一些“包装器”脚本放入您的 PATH 中的某个位置,并让该包装器脚本调用“java 14”java。

you wrote the program and compiled it using a higher version of jdk than you used to execute it.您编写程序并使用比执行它时使用的更高版本的 jdk 编译它。 Just go to build settings and set the compiler compliance level to the jdk you are using.只需 go 即可构建设置并将编译器合规级别设置为您正在使用的 jdk。 If you want to use JDK 14 instead of 8, just uninstall jdk 8 and java will use jdk14.如果您想使用 JDK 14 而不是 8,只需卸载 jdk 8,java 将使用 jdk14。 I hope this helped:)我希望这有帮助:)

You program didn't work because your computer points to an old version of java JDK in PATH.您的程序无法运行,因为您的计算机在 PATH 中指向旧版本的 java JDK。 You can just uninstall Java 8 and reinstall java 14. In cases, if don't want to delete the old one or you have manually changed the PATH variable, then:您可以卸载 Java 8 并重新安装 java 14。在某些情况下,如果不想删除旧的或者您手动更改了 PATH 变量,则:

Step 1: Delete old items of Java JDK from PATH.第 1 步:从 PATH 中删除 Java JDK 的旧项目。

Type "this pc" in the search bar next to the start button -> Right click "This PC", choose "Properties" -> click "Advanced system settings" on the left side bar -> click "Advanced" tab -> click "Environment Variables" button at bottom -> Modify the "Path" variable under System variables panel and DELETE all your old java path information(or any item in other variables with your old java information).在开始按钮旁边的搜索栏中输入“这台电脑”->右键单击“这台电脑”,选择“属性”->单击左侧栏中的“高级系统设置”->单击“高级”选项卡->单击底部的“环境变量”按钮 -> 修改系统变量面板下的“路径”变量并删除所有旧的 java 路径信息(或其他变量中包含旧 java 信息的任何项目)。 If you done right, java -version should not work right now.如果你做对了,java -version 现在应该不起作用。

Step 2: install Java JDK 14 from installer第 2 步:从安装程序安装 Java JDK 14

New Java PATH info will be automatically added to the PATH environment variable.新的 Java PATH 信息将自动添加到 PATH 环境变量中。 You don't need to manually update anything.您无需手动更新任何内容。 (If you do want, follow step 1 to change PATH) (如果确实需要,请按照步骤 1 更改 PATH)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM