简体   繁体   English

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提示。

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. 之后,您可以返回导入屏幕,它应该只显示。

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。

For Windows Platform: 对于Windows平台:

try Running the 64 Bit exe version of IntelliJ from a path similar to following. 尝试从类似于以下的路径运行IntelliJ的64位 exe版本。

note that it is available beside the default idea.exe 请注意它在默认idea.exe旁边可用

"C:\\Program Files (x86)\\JetBrains\\IntelliJ IDEA 15.0\\bin\\idea 64 .exe" “C:\\ Program Files(x86)\\ JetBrains \\ IntelliJ IDEA 15.0 \\ bin \\ idea 64 .exe”

link 链接

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!

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。

对于MacOS,这对我有用,而无需对特定Java版本进行硬编码:

launchctl setenv JAVA_HOME "$(jenv javahome)"

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

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

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