MavenReportException: JAVA_HOME not correctly set

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

MavenReportException: JAVA_HOME not correctly set

问题

我尝试了许多JDK版本,希望能解决这个问题,但无论我使用哪个Java版本,结果都是一样的。

> MavenReportException:创建归档时出错:找不到javadoc命令:环境变量JAVA_HOME设置不正确。

调试

以下是当前安装的JDK版本:
MavenReportException: JAVA_HOME not correctly set

我运行了:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

export PATH=$JAVA_HOME/bin:$PATH

java -version

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

javac -version

javac 1.8.0_265

mvn clean deploy -P release

MavenReportException: JAVA_HOME not correctly set

> MavenReportException:创建归档时出错:找不到javadoc命令:环境变量JAVA_HOME设置不正确。

Maven插件配置

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-compiler-plugin</artifactId>
	<configuration>
		<source>1.8</source>
		<target>1.8</target>
        <executable>${JAVA_HOME}/bin/javac</executable>
	</configuration>
</plugin>

尽管which javawhich javadoc指向/usr/bin,但可能是问题所在吗?

编辑 1

/bin的内容

MavenReportException: JAVA_HOME not correctly set

英文:

I've tried many JDK versions in order to solve this problem but it seems no matter which java i'm using the outcome is always the same.

> MavenReportException: Error while creating archive: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.

Debug

These are the jdk's currently installed:
MavenReportException: JAVA_HOME not correctly set

I ran :

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64

export PATH=$JAVA_HOME/bin:$PATH

java -version:

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

javac -version

javac 1.8.0_265

mvn clean deploy -P release

MavenReportException: JAVA_HOME not correctly set

> MavenReportException: Error while creating archive: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.

Maven Plugin Configuration

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-compiler-plugin</artifactId>
	<configuration>
		<source>1.8</source>
		<target>1.8</target>
        <executable>${JAVA_HOME}/bin/javac</executable>
	</configuration>
</plugin>

Although which java and which javadoc pointing to /usr/bin could that be the issue?

Edit 1

Contents of /bin

MavenReportException: JAVA_HOME not correctly set

答案1

得分: 6

以下是翻译好的内容:

我不知道这是否有所帮助,但在我的情况下,Maven出现了问题:
Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.2.0:jar 并且产生了异常:
MavenReportException: 生成Javadoc时出错:无法找到javadoc命令:JAVA_HOME环境变量未正确设置。

解决方案是找到导致问题的插件,
在我这里是 <artifactId>maven-javadoc-plugin</artifactId>,并添加以下内容:

				<configuration>
					<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
				</configuration>

其中${java.home}/usr/lib/jvm/java-11-openjdk-amd64/

插件的配置如下:

			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-javadoc-plugin</artifactId>
				<configuration>
					<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
				</configuration>
				<version>3.2.0</version>
				<executions>
					<execution>
						<id>attach-javadocs</id>
						<goals>
							<goal>jar</goal>
						</goals>
					</execution>
				</executions>
			</plugin>

并且目标成功执行。

英文:

I don't know if this helps, but in my case maven
Failed to execute goal org.apache.maven.plugins:maven-javadoc-plugin:3.2.0:jar and gave an exception:
MavenReportException: Error while generating Javadoc: Unable to find javadoc command: The environment variable JAVA_HOME is not correctly set.

The solution was to find the plugin that was causing the issue,
&lt;artifactId&gt;maven-javadoc-plugin&lt;/artifactId&gt; in my case and add the following:

				&lt;configuration&gt;
					&lt;javadocExecutable&gt;${java.home}/bin/javadoc&lt;/javadocExecutable&gt;
				&lt;/configuration&gt;

where ${java.home} was /usr/lib/jvm/java-11-openjdk-amd64/.

The plugin looked like:

			&lt;plugin&gt;
				&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
				&lt;artifactId&gt;maven-javadoc-plugin&lt;/artifactId&gt;
				&lt;configuration&gt;
					&lt;javadocExecutable&gt;${java.home}/bin/javadoc&lt;/javadocExecutable&gt;
				&lt;/configuration&gt;
				&lt;version&gt;3.2.0&lt;/version&gt;
				&lt;executions&gt;
					&lt;execution&gt;
						&lt;id&gt;attach-javadocs&lt;/id&gt;
						&lt;goals&gt;
							&lt;goal&gt;jar&lt;/goal&gt;
						&lt;/goals&gt;
					&lt;/execution&gt;
				&lt;/executions&gt;
			&lt;/plugin&gt;

and the goal was executed successfully.

答案2

得分: 0

请使用以下命令检查Maven的Java版本:

#mvn --version

它会显示类似以下内容:

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T01:19:05+05:30)
Maven home: /home/user/apache-maven-3.5.3
Java version: 1.8.0_121, vendor: Oracle Corporation
Java home: /home/user/jdk1.8.0_121/jre
Default locale: en_IN, platform encoding: UTF-8

在这里,您可以看到使用的JAVA版本及其位置。

英文:

Please check the java version for Maven using the following command:

#mvn --version

It will give something like:

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T01:19:05+05:30)
Maven home: /home/user/apache-maven-3.5.3
Java version: 1.8.0_121, vendor: Oracle Corporation
Java home: /home/user/jdk1.8.0_121/jre
Default locale: en_IN, platform encoding: UTF-8

Here, you can see which JAVA version is used and its location.

huangapple
  • 本文由 发表于 2020年9月2日 17:14:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63702419.html
匿名

发表评论

匿名网友

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

确定