[英]Where to add JAVA_HOME and MAVEN path variables in linux
I know there are a lot of articles about this topic but I wonder where to add the JAVA_HOME and MAVEN path variables. 我知道关于该主题的文章很多,但我想知道在哪里添加JAVA_HOME和MAVEN路径变量。
I have 3 files: 我有3个文件:
~/.bashrc
~/.bash_profile
/etc/profile
Which one should I use in order to add JAVA_HOME and export maven to the PATH? 我应该使用哪一个来添加JAVA_HOME并将maven导出到PATH?
export JAVA_HOME="/path/to/jdk"
export PATH=$JAVA_HOME/bin:$PATH
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. 唯一要做的就是将适当的Maven发行版的bin
文件夹( apache-maven-3.3.9/bin
)添加到您的path变量中。 The JAVA_HOME
location can be done either via environment variable. JAVA_HOME
位置可以通过环境变量来完成。 But the problem here is that it might influence other tools etc. So i would suggest to use $HOME/.mavenrc
file for such purposes. 但是这里的问题是,它可能会影响其他工具等。因此,我建议为此目的使用$HOME/.mavenrc
文件。
A .mavenrc
file can look like this: .mavenrc
文件如下所示:
export JAVA_HOME=/...LocationYouNeed
export MAVEN_OPTS="-Xmx768m ..."
By using this you can limit this only to Maven. 通过使用此选项,可以仅将其限制为Maven。 So in the end you only need to set the location of Maven via PATH
that's it. 因此,最后您只需要通过PATH
设置Maven的位置即可。
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. 从Maven 3.3.1开始,您可以在每个项目的基础上使用.mvn/jvm.config
来配置内存设置等,并将在项目中检入。 This means you can remove the MAVEN_OPTS
from your .mavenrc
file. 这意味着你可以删除MAVEN_OPTS
从.mavenrc
文件。
Usually you don't necessarily need to add JAVA_HOME/bin
to your path. 通常,您不一定需要将JAVA_HOME/bin
添加到您的路径。 If you need JAVA_HOME
only to run Maven you don't need to. 如果只需要JAVA_HOME
来运行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. 如果需要支持多个Maven版本,则可以在路径中定义一个位置,可以通过符号链接进行更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.