简体   繁体   English

构建新项目时,Java项目语言级别会自行更改-IntelliJ

[英]Java Project Language Level changing on its own when I build a new project - IntelliJ

Whenever I build a new project the project language level is automatically changed on it's own down to 6. Which means that whenever I try to build the project I get errors and warnings etc. I have been trying to change the project defaults but this does not help. 每当我构建新项目时,项目语言级别都会自动更改为6。这意味着,每当我尝试构建项目时,都会收到错误和警告等信息。我一直在尝试更改项目默认值,但这并没有救命。 I have also attempted to set the byte code version as 9 by default. 我还尝试将字节码版本默认设置为9。

This is my Project Structure before I set up a new project: 这是我建立新项目之前的项目结构:

这是我构建新项目之前的项目结构

After applying these settings I create a new hello world (console) application. 应用这些设置后,我将创建一个新的hello world(控制台)应用程序。 I then run the project and get these errors: 然后,我运行该项目并得到以下错误:

在此处输入图片说明

The only code in the main class is `public class Main { 主类中的唯一代码是`public class Main {

public static void main(String[] args) {
    System.out.println("Hello, World");
}
}

` `

I then go and check the project structure and see that the project language level has been changed. 然后,我去检查项目结构,看看项目语言级别已更改。 Why is it doing that and how do I stop this from happening? 为什么这样做?如何阻止这种情况发生? I have been researching this problem and even contacted the JetBrains forum but nothing helps. 我一直在研究此问题,甚至联系了JetBrains论坛,但没有任何帮助。 + I have also attempted to set the 'project byte version' as 9 by default but this also gets changed after I create a new project. +我还尝试将“项目字节版本”默认设置为9,但在创建新项目后也会更改。

This is what project structure looks like after running the project: 运行项目后,项目结构如下所示:

在此处输入图片说明

During my research I found out that if this is a maven project you can fix this by changing the pom.xml file but this is just a java console application. 在研究过程中,我发现如果这是一个Maven项目,则可以通过更改pom.xml文件来解决此问题,但这只是一个Java控制台应用程序。

These are the java compiler settings: 这些是Java编译器设置:

在此处输入图片说明

FYI by default it is set to 9; FYI默认设置为9; when the project is created it is set to nothing. 创建项目时,将其设置为空。

尝试使用File -> Other Settings-> Default Settings更改相同的设置

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

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