On "mvn install" command errors with and without "sudo" ("JAVA_HOME" and "–release" flag respectively)

huangapple go评论74阅读模式
英文:

On "mvn install" command errors with and without "sudo" ("JAVA_HOME" and "--release" flag respectively)

问题

根据您提供的内容,以下是翻译好的部分:

我有一个包含`.pom`文件的项目。根据说明,我应该首先运行`mvn install`命令。当我运行该命令时,我收到以下错误:

由于:org.apache.maven.plugin.MojoExecutionException引起的严重错误编译

由于:org.codehaus.plexus.compiler.CompilerException引发的无效标志:--release

由于:java.lang.IllegalArgumentException引发的无效标志:--release


但是,当我使用`sudo`运行该命令(`sudo mvn install`)时,我收到以下错误:

JAVA_HOME环境变量未正确定义
需要此环境变量来运行此程序
注意:JAVA_HOME应指向JDK而不是JRE


然而,`mvn -version`命令的结果如下:

Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 1.8.0_265, vendor: Private Build, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-42-generic", arch: "amd64", family: "unix"


另一方面,我已将以下内容添加到`~/.bashrc`文件中:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=/usr/share/maven/bin/mvn:$PATH
export PATH=$JAVA_HOME/bin:$PATH


`echo $JAVA_HOME`的结果是:

/usr/lib/jvm/java-8-openjdk-amd64


`java -version`的结果是:

openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~18.04-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)


此外,我考虑了许多与我的问题相关的帖子,例如[post1][1],[post2][2],[post3][3]和[post4][4](这些帖子与我的Ubuntu操作系统相反,是关于Windows上的Maven),或[post5][5](我没有相同的问题,因为我不在虚拟机上,也没有与`mvn -version`有关的任何问题。但是,mvn version命令指向了JRE,但所有环境变量都已正确设置为指向JDK)。但是,其中没有一个解决了我的问题。

希望这有助于您解决问题。如果您需要更多帮助,请随时提问。

英文:

I have a project that contains the .pom file. Based on the instruction, I should run the mvn install command first. When I run the command I get the following error:

Caused by: org.apache.maven.plugin.MojoExecutionException: Fatal error compiling   

Caused by: org.codehaus.plexus.compiler.CompilerException: invalid flag: --release

Caused by: java.lang.IllegalArgumentException: invalid flag: --release

But, when I run the command with sudo (sudo mvn install), I get the following error:

The JAVA_HOME environment variable is not defined correctly
This environment variable is needed to run this program
NB: JAVA_HOME should point to a JDK not a JRE

However, the result of mvn -version command is as follows:

Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 1.8.0_265, vendor: Private Build, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.4.0-42-generic", arch: "amd64", family: "unix"

On the other hand, I've added the followings to ~/.bashrc file:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export PATH=/usr/share/maven/bin/mvn:$PATH
export PATH=$JAVA_HOME/bin:$PATH

The result of echo $JAVA_HOME is:

/usr/lib/jvm/java-8-openjdk-amd64

and the result of java -version is :

openjdk version "1.8.0_265"
OpenJDK Runtime Environment (build 1.8.0_265-8u265-b01-0ubuntu2~18.04-b01)
OpenJDK 64-Bit Server VM (build 25.265-b01, mixed mode)

Besides, I've considered many related posts to my issue, such as post1, post2, post3, and post4 (which are about maven in windows, opposite to my Ubuntu OS) or post5 (that I have not the same problem, as I am not on a VM or any problem with mvn -version. However, mvn version command points to JRE, but all environment variables have been set correctly to point to the JDK). But, none of them resolve it.

答案1

得分: 0

我有一个类似的设置,而且它是有效的。您可以尝试这个设置,在可能的情况下尝试重新启动系统。

export JAVA_HOME=/usr/lib/jvm/jdk-11.0.8

export PATH=${PATH}:${JAVA_HOME}/bin

英文:

I have a similar kind of setting, and that is working. You can try this setting, try restarting the system if possible.

export JAVA_HOME=/usr/lib/jvm/jdk-11.0.8

export PATH=${PATH}:${JAVA_HOME}/bin

答案2

得分: 0

当您使用sudo命令运行命令时,来自当前(非特权)shell的环境变量不会传递到运行命令的环境中。

尝试这样做:

$ export FOO=BAR
$ sudo export

您将看不到变量列表中有FOO

因此,当您运行sudo mvn ...时,JAVA_HOME设置不会传递给Maven,Maven也会显示此信息。

如果您想要传递所有环境变量,可以使用sudo -E或类似选项。这在sudo的手册条目中有解释。

英文:

When you run a command using sudo, the environment variables from your current (non-privileged) shell are NOT passed through to the environment in which the command is run.

Try this:

$ export FOO=BAR
$ sudo export

and you won't see FOO in the list of variables.

So, when you run sudo mvn ... the JAVA_HOME setting is not being passed to Maven, and it says so.

If you want to pass all of the environment variables, use sudo -E or similar. This is explained in the manual entry for sudo.

huangapple
  • 本文由 发表于 2020年10月15日 20:52:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/64372027.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定