在Linux的何处添加JAVA_HOME和MAVEN路径变量 [英] Where to add JAVA_HOME and MAVEN path variables in linux
问题描述
我知道有很多关于该主题的文章,但是我想知道在哪里添加JAVA_HOME和MAVEN路径变量.
I know there are a lot of articles about this topic but I wonder where to add the JAVA_HOME and MAVEN path variables.
我有3个文件:
~/.bashrc
~/.bash_profile
/etc/profile
我应该使用哪一个来添加JAVA_HOME并将maven导出到PATH?
Which one should I use in order to add JAVA_HOME and export maven to the PATH?
export JAVA_HOME="/path/to/jdk"
export PATH=$JAVA_HOME/bin:$PATH
推荐答案
唯一要做的就是添加相应Maven发行版( apache-maven-3.3.的
)添加到您的路径变量. bin
文件夹.9/bin JAVA_HOME
位置可以通过环境变量来完成.但是这里的问题是,它可能会影响其他工具等.因此,我建议出于这种目的使用 $ HOME/.mavenrc
文件.
The only thing to do is to add the bin
folder of the appropriate Maven distribution (apache-maven-3.3.9/bin
) to your path variable. The JAVA_HOME
location can be done either via environment variable. But the problem here is that it might influence other tools etc. So i would suggest to use $HOME/.mavenrc
file for such purposes.
一个 .mavenrc
文件如下所示:
export JAVA_HOME=/...LocationYouNeed
export MAVEN_OPTS="-Xmx768m ..."
通过使用此选项,您只能将其限制为Maven.所以最后,您只需要通过 PATH
设置Maven的位置即可.
By using this you can limit this only to Maven. So in the end you only need to set the location of Maven via PATH
that's it.
从 Maven 3.3.1 开始,您可以使用 .mvn/jvm.config
可以在每个项目的基础上配置内存设置等,并将在您的项目中检入.这意味着您可以从 .mavenrc
文件中删除 MAVEN_OPTS
.
Starting with Maven 3.3.1 you can use the .mvn/jvm.config
to configure memory settings etc. on a per project base which will be checked in with your project. This means you can remove the MAVEN_OPTS
from your .mavenrc
file.
通常,您不一定需要在路径中添加 JAVA_HOME/bin
.如果只需要 JAVA_HOME
来运行Maven,则不需要.
Usually you don't necessarily need to add JAVA_HOME/bin
to your path. If you need JAVA_HOME
only to run Maven you don't need to.
如果需要支持多个Maven版本,则可以在路径中定义一个位置,可以通过符号链接进行更改.
If you need to support multiple Maven versions you can define a location in your path which you can change via a symbolic link.
这篇关于在Linux的何处添加JAVA_HOME和MAVEN路径变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!