在 Eclipse 中设置 MAVEN_HOME
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26460062/
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
set MAVEN_HOME in eclipse
提问by Bailey
I have this line of code in a project in eclipse & it's giving me error.
我在 eclipse 的一个项目中有这行代码 & 它给了我错误。
Invoker invoker = new DefaultInvoker();
invoker.setMavenHome(new File(System.getenv("MAVEN_HOME"))); //giving error
So I ran and its giving blank line as output
所以我跑了,它给空行作为输出
echo $MAVEN_HOME
However, I am able to run other maven projects through command prompt and through eclipse. I have following question..
但是,我可以通过命令提示符和 eclipse 运行其他 Maven 项目。我有以下问题..
Q 1. what is the difference between the following two commands
Q 1. 下面两个命令有什么区别
whereis maven
maven: /etc/maven /usr/share/maven
& when I run
&当我跑步时
whereis mvn
mvn: /usr/bin/mvn /usr/bin/X11/mvn /usr/share/man/man1/mvn.1.gz
Q 2. what do I need to put in .bashrc... please tell me exactly...
Q 2. 我需要在 .bashrc 中放入什么...请准确地告诉我...
this is my current content of .bashrc file
这是我当前的 .bashrc 文件内容
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/
export JAVA_HOME
export PATH
EDIT
编辑
mvn -version
Apache Maven 3.0.4
Maven home: /usr/share/maven
Java version: 1.7.0_65, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre
Thanks :)
谢谢 :)
采纳答案by dds
Just to use in eclipse you can add this in Window -> Preferences -> Java -> Build Path -> Classpath Variables.
只是为了在 Eclipse 中使用,您可以在 Window -> Preferences -> Java -> Build Path -> Classpath Variables 中添加它。
Just add new variable with name MAVEN_HOME
.
只需添加名为 name 的新变量MAVEN_HOME
。
But for executions you need to set in in Run/Debug configuration - probably that's what you need.
但是对于执行,您需要在运行/调试配置中进行设置 - 可能这就是您所需要的。
whereis maven
is about directory, and
是关于目录,和
whereis mvn
is about executable file.
是关于可执行文件的。
For .bashrc:
对于 .bashrc:
MAVEN_HOME=/usr/share/maven
export MAVEN_HOME
回答by onof
Don't set the MAVEN_HOME
in bashrc
file but set it in the Environment tab of the launcher configuration of Eclipse.
不要设置MAVEN_HOME
inbashrc
文件,而是在 Eclipse 启动器配置的环境选项卡中设置它。
The .bashrc file is for the bash environment
.bashrc 文件用于 bash 环境
回答by GPrathap
Basically invoker.setMavenHome(MAVEN_HOME);
this needs the home directory where you have installed maven. If you need to find where is the home directory of maven. You can you use following approaches as you tried.
基本上invoker.setMavenHome(MAVEN_HOME);
这需要您安装 maven 的主目录。如果需要查找maven的主目录在哪里。您可以尝试使用以下方法。
whereis maven
This will be showing where is the location which maven has been installed into your computer.
这将显示 Maven 安装到您的计算机的位置。
maven: /etc/maven /usr/share/maven