如何指示Maven使用JDK而不是JAVA_HOME中指定的JDK? [英] How to instruct Maven to use JDK other than the one specified at JAVA_HOME?
问题描述
目前我的 JAVA_HOME
设置为1.4.2的JDK。
Currently my JAVA_HOME
is set to a JDK that is 1.4.2.
要运行Maven 3,我需要1.5及以上。
To run Maven 3, I would need 1.5 and above.
有没有办法指导我的Maven安装使用除了更改 JAVA_HOME
环境变量之外安装的另一个JDK?
Is there any way to instruct my Maven installation to use another JDK that is installed other than changing the JAVA_HOME
environment variable?
推荐答案
这几乎就是这样做的。我假设你的意思是你不想改变你的全局JAVA_HOME。没关系。你只需要为Maven设置一个不同的JAVA_HOME。您可以通过在 / etc / mavenrc
或〜/ .mavenrc
(Linux)或<创建文件来轻松完成此操作。 code>%HOME%\mavenrc_pre.bat (Windows),其中定义了相应的JAVA_HOME。除非你定义了一个名为 MAVEN_SKIP_RC
的变量,否则Maven会在启动时执行它们。您也可以直接修改Maven启动脚本,但没有充分的理由,因为它为您提供了这些不错的挂钩。
That's pretty much the way to do it. I assume you mean you don't want to change your global JAVA_HOME. That's fine. You just need to set a different JAVA_HOME for Maven. You can easily do that by creating a file at /etc/mavenrc
or ~/.mavenrc
(Linux) or %HOME%\mavenrc_pre.bat
(Windows) with the appropriate JAVA_HOME defined in it. Maven executes those on startup if they exist unless you've defined a variable named MAVEN_SKIP_RC
. You could also modify the Maven startup scripts directly, but there's no good reason for that since it gives you these nice hooks.
这篇关于如何指示Maven使用JDK而不是JAVA_HOME中指定的JDK?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!