Intellij Idea:导入 Gradle 项目 - 尚未定义 JAVA_HOME
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31215452/
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
Intellij Idea: Importing Gradle project - getting JAVA_HOME not defined yet
提问by bentobox
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:
从外壳:
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 variable,但没有 Project SDK 提示。
采纳答案by visola
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. After that, you can go back to the import screen and it should just show up.
只需单击New...
下拉菜单右侧的按钮并将其指向您的 JDK。之后,您可以返回导入屏幕,它应该会显示出来。
回答by hraut
Try starting IntelliJ from terminal. You can find application file under: /Applications/IntelliJ\ IDEA\ 14.app/Contents/MacOS
尝试从终端启动 IntelliJ。您可以在以下位置找到应用程序文件:/Applications/IntelliJ\ IDEA\ 14.app/Contents/MacOS
回答by rizzletang
Make sure you have a jdk setup. To do this, create a new project and then go to file -> project structure. From there you can add a new jdk. Once that is setup, go back to your gradle project and you should have a jdk to select in the 'Gradle JVM' field.
确保您有 jdk 设置。为此,请创建一个新项目,然后转到文件 -> 项目结构。从那里你可以添加一个新的 jdk。设置完成后,返回到您的 gradle 项目,您应该有一个 jdk 可以在“Gradle JVM”字段中进行选择。
回答by akhouri
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!
并且可以在那里定义项目 SDK!
回答by gk0
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)
- Add login env variable by executing:
launchctl setenv JAVA_HOME "/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home"
- 从终端 /Applications/IntelliJ IDEA 14.app/Contents/MacOS 启动您的智能(这将选择您的 bash 环境变量)
- 通过执行添加登录环境变量:
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。
回答by Iman
For WindowsPlatform:
对于Windows平台:
try Running the 64 Bitexe 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\idea64.exe"
“C:\Program Files (x86)\JetBrains\IntelliJ IDEA 15.0\bin\idea 64.exe”
回答by Dmitry Chornyi
For MacOS this worked for me without the need to hardcode a particular Java version:
对于 MacOS,这对我有用,无需对特定 Java 版本进行硬编码:
launchctl setenv JAVA_HOME "$(jenv javahome)"