Java 如何更改 IntelliJ IDEA 默认 JDK?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18987228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I change the IntelliJ IDEA default JDK?
提问by GamerJosh
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 作为我的开发环境,使用 Maven 进行依赖管理。我经常在 IDEA 之外构建我的项目结构(目录、poms 等),然后使用Import project from external model
. 这很好用,除了在我的 poms 中我指定 maven-compiler-plugin 应该使用 JDK 1.6,当我导入时,IDEA 通知我 theLanguage Level Changed
和 that Language level changes will take effect on project reload
,然后提示重新加载项目。这很烦人,因为我总是使用相同的 JDK 版本。
How do I change the default JDK that IntelliJ IDEA uses, so that I don't have to reload my project every time I import a new project?
如何更改 IntelliJ IDEA 使用的默认 JDK,以便每次导入新项目时都不必重新加载项目?
采纳答案by GamerJosh
This setting is changed in the "Default Project Structure..." dialog. Navigate to "File" -> "Other Settings" -> "Default Project Structure...".
此设置在“默认项目结构...”对话框中更改。导航到“文件”->“其他设置”->“默认项目结构...”。
Next, modify the "Project language level" setting to your desired language level.
接下来,将“项目语言级别”设置修改为所需的语言级别。
IntelliJ IDEA 12 had this setting in "Template Project Structure..." instead of "Default Project Structure..."
IntelliJ IDEA 12 在“模板项目结构...”而不是“默认项目结构...”中有此设置
回答by Do Nhu Vy
- I am using IntelliJ IDEA 14.0.3, and I also have same question. Choose menu
File
\Other Settings
\Default Project Structure...
- 我正在使用 IntelliJ IDEA 14.0.3,我也有同样的问题。选择菜单
File
\Other Settings
\Default Project Structure...
- Choose
Project
tab, sectionProject language level
, choose level from dropdown list, this setting isdefault for all new project
.
- 选择
Project
选项卡,部分Project language level
,从下拉列表中选择级别,此设置为default for all new project
。
回答by ethemsulan
回答by Jorgesys
I have found out that in recent versions of IntelliJ IDEA requires Java 1.8 but is not configured by default.
我发现在 IntelliJ IDEA 的最新版本中需要 Java 1.8,但默认情况下未配置。
We can change the path or configure from Project Settings
> Project
> Project SDK
我们可以改变从路径或配置Project Settings
> Project
>Project SDK
here we can edit or add the JDK′s path.
在这里我们可以编辑或添加JDK的路径。
(in my case the path is located in C:\Program Files\Java\jdk1.8.0_102
)
(在我的情况下,路径位于C:\Program Files\Java\jdk1.8.0_102
)
回答by barclay
One other place worth checking: Look in the pom.xml for your project, if you are using Maven compiler plugin, at the source/target config and make sure it is the desired version of Java. I found that I had 1.7 in the following; I changed it to 1.8 and then everything compiled correctly in IntelliJ.
另一个值得检查的地方:如果您使用的是 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>
回答by Gayan Weerakutti
回答by knollmaj
The above responses were very useful, but after all settings, the project was running with the wrong version. Finally, I noticed that it can be also configured in the Dependencies window. Idea 2018.1.3 File -> Project Structure -> Modules -> Sources andDependencies.
上面的回答很有用,但是经过所有设置,项目运行的版本不对。最后,我注意到它也可以在 Dependencies 窗口中进行配置。Idea 2018.1.3 File -> Project Structure -> Modules -> Sources andDependencies。
回答by Duracell De Monaco
To change the JDK version of the Intellij-IDE himself:
要自己更改 Intellij-IDE 的 JDK 版本:
Start the IDE -> Help -> Find Action
启动IDE -> Help -> Find Action
than type:
比类型:
Switch Boot JDK
or (depend on your version)
或(取决于您的版本)
Switch IDE boot JDK
回答by MrKulli
For latest version intellij, to set default jdk/sdk for new projects go to
对于最新版本的 Intellij,要为新项目设置默认 jdk/sdk,请转到
Configure->Structure for New Projects -> Project Settings -> Project SDK
Configure->Structure for New Projects -> Project Settings -> Project SDK