Intellij Idea:导入Gradle项目 - 尚未定义JAVA_HOME

本文翻译自:Intellij Idea: Importing Gradle project - getting JAVA_HOME not defined yet

Intellij Idea 14.1.4 Mac OS X Yosemite 10.10.3 and later. Intellij Idea 14.1.4 Mac OS X Yosemite 10.10.3及更高版本。

From the IDE: 从IDE:

Import Project ->
(Chosen directory to import) ->
Import project from external model, Gradle ->
Gradle Home: /usr/local/Cellar/gradle/2.4/libexec
Gradle JVM: Use JAVA_HOME (not defined yet)

From shell: 来自shell:

echo $JAVA_HOME

/Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home

(defined in .profile: export JAVA_HOME="$(/usr/libexec/java_home -v 1.8)" (在.profile中定义:export JAVA_HOME =“$(/ usr / libexec / java_home -v 1.8)”

What am I missing. 我错过了什么 I have checked other discussions in SO, for example, Intellij JAVA_HOME variable , but don't have Project SDK prompt. 我已经检查了SO中的其他讨论,例如, Intellij JAVA_HOME变量 ,但是没有Project SDK提示。


#1楼

参考:https://stackoom.com/question/26yZ2/Intellij-Idea-导入Gradle项目-尚未定义JAVA-HOME


#2楼

Try starting IntelliJ from terminal. 尝试从终端启动IntelliJ。 You can find application file under: /Applications/IntelliJ\\ IDEA\\ 14.app/Contents/MacOS 您可以在以下位置找到应用程序文件:/ Applications / IntelliJ \\ IDEA \\ 14.app/Contents/MacOS


#3楼

Make sure you have a jdk setup. 确保你有一个jdk设置。 To do this, create a new project and then go to file -> project structure. 为此,请创建一个新项目,然后转到文件 - >项目结构。 From there you can add a new jdk. 从那里你可以添加一个新的jdk。 Once that is setup, go back to your gradle project and you should have a jdk to select in the 'Gradle JVM' field. 设置好之后,返回到gradle项目,你应该在'Gradle JVM'字段中选择一个jdk。


#4楼

You need to setup a SDK for Java projects, like @rizzletang said, but you don't need to create a new project, you can do it from the Welcome screen. 你需要为Java项目设置一个SDK,比如@rizzletang说,但你不需要创建一个新项目,你可以从Welcome屏幕上完成。

On the bottom right, select Configure > Project Defaults > Project Structure : 在右下角,选择Configure > Project Defaults > Project Structure 在此输入图像描述

Picking the Project tab on the left will show that you have no SDK selected: 选择左侧的“ Project选项卡将显示您没有选择SDK:

在此输入图像描述

Just click the New... button on the right hand side of the dropdown and point it to your JDK. 只需单击下拉列表右侧的“ New...按钮,然后将其指向JDK即可。 After that, you can go back to the import screen and it should just show up. 之后,您可以返回导入屏幕,它应该只显示。


#5楼

Just to add completness to the above selected answer, one can also go the 'Project Setting' windows (if not on the Welcome screen) in IntelliJ IDEA by clicking: 只需在上面选择的答案中添加完整性,也可以通过单击以下方式进入IntelliJ IDEA中的“项目设置”窗口(如果不在欢迎屏幕上):

File > Project Structure (Ctrl + Alt + Shift + S) 文件>项目结构(Ctrl + Alt + Shift + S)

And can define Project SDK there! 并且可以在那里定义Project SDK!


#6楼

If you'd like to have your JAVA_HOME recognised by intellij, you can do one of these: 如果您想通过intellij识别您的JAVA_HOME,您可以执行以下操作之一:

  • Start your intellij from terminal /Applications/IntelliJ IDEA 14.app/Contents/MacOS (this will pick your bash env variables) 从终端/ Applications / IntelliJ IDEA 14.app/Contents/MacOS启动你的intellij(这将选择你的bash env变量)
  • Add login env variable by executing: launchctl setenv JAVA_HOME "/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home" 通过执行以下launchctl setenv JAVA_HOME "/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home"添加登录env变量: launchctl setenv JAVA_HOME "/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home"

As others have answered you can ignore JAVA_HOME by setting up SDK in project structure. 正如其他人已经回答的那样,您可以通过在项目结构中设置SDK来忽略JAVA_HOME。

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 深蓝海洋 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值