I use IntelliJ IDEA as my development environment, and Maven for dependency management. I frequently build my project structure (directories, poms, etc) outside of IDEA and then import the project into IDEA using Import project from external model. This works great, except that in my poms I specify that the maven-compiler-plugin should use JDK 1.6, and when I import, IDEA informs me that the Language Level Changed and that Language level changes will take effect on project reload, and then prompts to reload the project. This is annoying because I always use the same JDK version.

我如何改变IntelliJ IDEA使用的默认JDK,以便我不必每次导入新项目时都重新加载我的项目?


当前回答

另一个值得检查的地方:如果您使用Maven编译器插件,请在项目的pom.xml中查看源/目标配置,并确保它是所需的Java版本。我发现我有1.7分;我将其更改为1.8,然后在IntelliJ中正确编译所有内容。

<build>
<plugins>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
            <source>1.8</source>
            <target>1.8</target>
            <encoding>UTF-8</encoding>
        </configuration>
    </plugin>
</plugins>
</build>

其他回答

在“新项目结构”对话框中更改此设置。导航到“文件”->“新项目设置”->“结构…”

接下来,适当修改“项目SDK”和“项目语言级别”。


以前版本的IntelliJ IDEA在“文件”->“其他设置”->“默认项目结构…”中有此设置。

IntelliJ IDEA 12在“模板项目结构…”而不是“默认项目结构…”

我使用的是IntelliJ IDEA 14.0.3,我也有同样的问题。选择菜单文件\其他设置\默认项目结构…



选择项目选项卡,部分项目语言级别,从下拉列表中选择级别,此设置为所有新项目的默认设置。

上面的回答非常有用,但在所有设置之后,项目运行的版本是错误的。最后,我注意到它也可以在Dependencies窗口中配置。 2018.1.3文件->项目结构->模块->来源和依赖项。

下载并解压一个JDK存档文件(.tar.gz),并将其作为SDK添加到“项目结构”对话框中(Ctrl+Alt+Shift+S)

点击动图放大

还要确保设置适当的“项目语言级别”。我在创建动图的时候忘记了。

>项目>项目语言级别

对于Java 8,设置为8,对于Java 9,设置为9,依此类推。

在我的linux机器上,我使用这样的脚本:

export IDEA_JDK=/opt/jdk14
/idea-IC/bin/idea.sh