JAVA_HOME 和 Maven 依赖项的奇怪问题

发布于 2024-10-24 05:10:49 字数 730 浏览 2 评论 0原文

我将 JAVA_HOME 变量设置为 C:\Program Files\Java\jre6\ 当我在项目上运行 maven package 时,它​​告诉我它无法解析依赖项

[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.0:compile (default) on project roo: Execution default of goal o
rg.codehaus.mojo:aspectj-maven-plugin:1.0:compile failed: Plugin org.codehaus.mojo:aspectj-maven-plugin:1.0 or one of its dependencies
could not be resolved: Could not find artifact com.sun:tools:jar:1.4.2 at specified path C:\Program Files\Java\jre6/../lib/tools.jar ->
[Help 1]

,因此它假设 JAVA_HOME 实际上是一级比实际更深,我查看了maven本地存储库,发现log4j 1.2.16使用了这个依赖项

我试图让JAVA_HOME看起来像C:\Program Files\Java\jre6\bin\但是然后maven就无法运行,它告诉我我的JAVA_HOME路径错误

I have JAVA_HOME variable set to C:\Program Files\Java\jre6\ when I run maven package on the project it tells me that it can't resolve dependency

[ERROR] Failed to execute goal org.codehaus.mojo:aspectj-maven-plugin:1.0:compile (default) on project roo: Execution default of goal o
rg.codehaus.mojo:aspectj-maven-plugin:1.0:compile failed: Plugin org.codehaus.mojo:aspectj-maven-plugin:1.0 or one of its dependencies
could not be resolved: Could not find artifact com.sun:tools:jar:1.4.2 at specified path C:\Program Files\Java\jre6/../lib/tools.jar ->
[Help 1]

so it assumes that JAVA_HOME is actually one level deeper than it actually is, I have looked through maven local repository and found that log4j 1.2.16 uses this dependency

I tried to make JAVA_HOME look like C:\Program Files\Java\jre6\bin\ but then maven wouldnt run, it told me that my JAVA_HOME path was wrong

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(15

梦在深巷 2024-10-31 05:10:50

编写、编译和打包java程序需要JDK,因为必要的工具仅随JDK(Java开发工具包)一起分发。 JRE(Java运行时环境)只需要运行java程序。

to write, compile and package java program's a JDK is needed, because the necessary tools are only distributed with a JDK (Java Development Kit). The JRE (Java Runtime Environment) is only needed to run a java program.

╰ゝ天使的微笑 2024-10-31 05:10:50

在不弄乱 JAVA_HOME 环境变量的情况下,以下是我修复它的方法。

安装1.6.x jdk。

在已安装的 JRE 下的 Eclipse/Preferences 中,添加 JDK 条目并将其设为默认值(将位置设置为 JDK 文件夹,例如 C:\Program Files\Java\jdk1.6.0_34

编辑属性并添加 JDK_HOME/ 。

或者,假设安装了 jdk,您可以将 JDK/lib/tools.jar 添加到现有默认 JRE 的系统库列表中

Without messing with the JAVA_HOME env variable, here is how I was able to fix it.

Install the 1.6.x jdk.

In Eclipse/Preferences under installed JREs, add an entry for the JDK and make it the default (set the location to the JDK folder, eg., C:\Program Files\Java\jdk1.6.0_34

Edit the properties and add JDK_HOME/lib/tools.jar to the system libraries list.

Alternately, assuming the jdk is installed, you can add the JDK/lib/tools.jar to the system libraries list of your existing default JRE

知足的幸福 2024-10-31 05:10:50

在键入 java -version 时,我能够在命令提示符中看到适当的响应,但在键入 mvn -version 时出现此错误。

就我而言,这是一个愚蠢的错误。 JAVA_HOME 环境变量这些天都指向 ..\jdk\bin 文件夹,这导致了问题。从 JAVA_HOME 变量值中删除 bin 后,我就可以使用 Maven 了。

注意:系统变量路径应包含指向 JDK 的 bin 文件夹的值。

问候,
巴拉吉·K

I was able to see the appropriate response in command prompt while keying in java -version but got this error while typing mvn -version.

In my case, it was a silly mistake. JAVA_HOME environment variable was pointing to the ..\jdk\bin folder all these days and that caused the problem. After removing the bin from the JAVA_HOME variable's value, I could able to work with Maven.

Note: System variable path should contain the value that points to the bin folder of your JDK.

Regards,
Balaji.K

长不大的小祸害 2024-10-31 05:10:50

配置 JAVA 环境变量的正确方法是:-

  1. 将 JAVA_HOME 设置为您的“jdk 文件夹”\jre
  2. 将“jdk 文件夹”\bin 添加到您的 PATH 用户环境变量

JAVA_HOME 是需要来自 JRE\bin 的“java.exe”的位置文件夹。
PATH 是寻找 javac.exe,它需要来自 JDK\bin 文件夹。

这也确保了 JDK 和 JRE 兼容

Proper way to configure JAVA environment variables is :-

  1. Set JAVA_HOME to Your "jdk folder"\jre
  2. Add "jdk folder"\bin to Your PATH user environment variable

JAVA_HOME is location of "java.exe" which needs to come from JRE\bin folder.
PATH is to look for javac.exe which needs to come from JDK\bin folder.

This also ensures JDK and JRE are compatible

二智少女猫性小仙女 2024-10-31 05:10:50

要运行 Maven - 您需要配置环境变量 JAVA_HOME 以指向 JDK,

例如 JAVA_HOME=C:\Program Files\Java\jdk1.7.0_25

另外您还需要 C:\Program Files\Java\jdk1.7.0_25\ bin 包含在 PATH 环境变量中。

问候,
迪潘

For Maven to run - You need to configure an environment variable JAVA_HOME to point to a JDK

e.g. JAVA_HOME=C:\Program Files\Java\jdk1.7.0_25

Also you need the C:\Program Files\Java\jdk1.7.0_25\bin included in the PATH environment variable.

Regards,
Dipan

尸血腥色 2024-10-31 05:10:50

我遇到过类似的问题,以下解决了问题:

JAVA_HOME = C:\Program Files\java\jdk
M2_HOME= C:\Program Files\apache-maven

inside path = ....%JAVA_HOME%\bin;%M2_HOME%\bin;

这解决了问题。

I have faced similar issue , the following resolved the issue:

JAVA_HOME = C:\Program Files\java\jdk
M2_HOME= C:\Program Files\apache-maven

inside path = ....%JAVA_HOME%\bin;%M2_HOME%\bin;

this solved the issue.

上课铃就是安魂曲 2024-10-31 05:10:50

我有一个类似的问题,答案就是这么简单;

maven 找不到 JAVA_HOME 变量,直到我意识到我将 Java 路径写入了路径变量中。
因此,我的“错误:在您的环境中找不到 JAVA_HOME...”的答案是创建一个名为 JAVA_HOME 的新变量。也许这对傻瓜来说是失败的,但我花了一个小时才意识到......

i had a similar Problem and the answer is that easy;

maven couldn´t find the JAVA_HOME varaiable, until i realized, that i wrote the Java path into my path-variable.
So the answer to my "ERROR: JAVA_HOME not found in you Environment..." was to create a new variable with Name JAVA_HOME. Maybe thats a failure for dummies but it took me one hour to realize ...

呆° 2024-10-31 05:10:50

您还应该确保 Java 库位于项目的类路径中。导航到项目的属性 -> java 构建路径 -> 库选项卡。检查jdk库是否列出。如果没有添加它。这也可能是此类错误的原因。

You should also make sure Java library is on your project's classpath. Navigate to project's properties->java build path->libraries tab. Check if jdk library is listed out. If not add it. This can also be the cause of such error.

白鸥掠海 2024-10-31 05:10:50

我刚刚在为我的命令行 Maven 项目进行 Java 自动更新(在 Windows 7 上)后遇到了这个问题(与 Eclipse 中的 maven 版本不同)。 JRE自动更新删除了我的系统JAVA_HOME环境变量指向的JDK下的jre文件夹。由于没有找到jre,maven默认使用新安装的JRE(仍然不知道如何)。我恢复了 JDK 目录下的 jre 文件夹,并删除了对 C:\ProgramData\Oracle\Java\javapath 的引用,该引用已添加到系统 Path 变量的开头,maven 构建恢复正常。

I just had this problem after a Java auto-update (on Windows 7) for my command line Maven projects (separate issue than the maven version within Eclipse). The JRE auto-update removed the jre folder under the JDK that was pointed to by my system JAVA_HOME environment variable. Since the jre wasn't found, maven was defaulting to the newly installed JRE (still haven't figured out how). I restored the jre folder under my JDK directory and removing a reference to C:\ProgramData\Oracle\Java\javapath which had been added to the start of the system Path variable, and the maven builds returned to normal.

乖乖哒 2024-10-31 05:10:49

您将需要 Java JDK 而不仅仅是 JRE。您可以在 Oracle 的 Java 页面 获取一个

编辑:
来自 Maven 属性指南

${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example:
<jvm>${java.home}../bin/java.exe</jvm>

对于 c:\jdk 中的 JDK,maven ${java.home} 指向 c:\jdk\jre

You will need a Java JDK not just a JRE. You can get one at Oracle's Java Page

Edit:
From the Maven Properties Guide:

${java.home} specifies the path to the current JRE_HOME environment use with relative paths to get for example:
<jvm>${java.home}../bin/java.exe</jvm>

And with a JDK for example in c:\jdk the maven ${java.home} is pointing to c:\jdk\jre

风情万种。 2024-10-31 05:10:49

我还发现这对我有帮助。

...
对于 Eclipse,您需要验证已安装的 JRE 是否正在使用 JDK 安装。

这意味着在配置选项中...
窗口/首选项/Java/已安装的 JRE
...您应该指向 JDK 安装。

您需要更改jdk中jre的路径。对于%Program Files%\Java\jdk1.6.0_25\jre

I also found this that helped me out.

...
With Eclipse, you need to verify that Installed JREs are using JDK installs.

This means that in the configuration option...
Window / Preferences / Java / Installed JREs
...You should point to a JDK installation.

You need to change the path to the jre within the jdk. for %Program Files%\Java\jdk1.6.0_25\jre

虚拟世界 2024-10-31 05:10:49

java.home 变量可以从您的项目 pom.xml 进一步派生。仔细检查您的 Maven 编译器插件参考。我在尝试构建时遇到了同样的问题,抱怨找不到 javac。我的java.home、JAVA_HOME都设置正确。

对我来说,修复的是纠正 pom.xml 我最终进行了以下更改:

            <!-- Original Version of compiler plugin reference -->
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>${default.java.version}</source>
                <target>${default.java.version}</target>
                <showDeprecation>false</showDeprecation>
                <executable>${default.java.home}/bin/javac</executable>
                <compilerVersion>${default.java.version}</compilerVersion>
                <fork>true</fork>
            </configuration>

            <!-- MODIFIED Version of compiler plugin reference -->
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>

                <!-- SPECIFY A DISCRETE VERSION!! Do not let it derive it! -->
                <source>1.6</source>
                <target>1.6</target>

                <!--
                  <showDeprecation>false</showDeprecation>
                  <executable>${default.java.home}/bin/javac</executable>
                  <compilerVersion>${default.java.version}</compilerVersion>
                  <fork>true</fork>
               -->
            </configuration>

The java.home variable can be further derived from your project pom.xml. Double-Check your maven compiler-plugin reference. I had this same problem, when trying to build, about it whining it cannot find javac. My java.home, JAVA_HOME were all set correctly.

What turned out to be FIX for me was correcting the pom.xml I ended up making the following changes:

            <!-- Original Version of compiler plugin reference -->
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>
                <source>${default.java.version}</source>
                <target>${default.java.version}</target>
                <showDeprecation>false</showDeprecation>
                <executable>${default.java.home}/bin/javac</executable>
                <compilerVersion>${default.java.version}</compilerVersion>
                <fork>true</fork>
            </configuration>

            <!-- MODIFIED Version of compiler plugin reference -->
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.0.2</version>
            <configuration>

                <!-- SPECIFY A DISCRETE VERSION!! Do not let it derive it! -->
                <source>1.6</source>
                <target>1.6</target>

                <!--
                  <showDeprecation>false</showDeprecation>
                  <executable>${default.java.home}/bin/javac</executable>
                  <compilerVersion>${default.java.version}</compilerVersion>
                  <fork>true</fork>
               -->
            </configuration>
一江春梦 2024-10-31 05:10:49

此问题也出现在 Intellij IDEA(IDEA 11.x ~ Windows 7 ~ Java 7)中。指定 systempath 属性引用 IDEA jre ...

一个稳定的解决方案是在 $HOME/.m2/settings.xml 下创建本地 Maven 配置文件

<profiles>
  <profile>
    <id>dev</id>
      <activation>
        <activeByDefault>true</activeByDefault>
          <jdk>NUMERIC_VERSION</jdk>
        </activation>
        <properties>
          <java.home>                   
            <!-- ABSOLUTE_PATH_HERE -->
          </java.home> 
        </properties>
  </profile>
</profiles>

This issue also crops up in Intellij IDEA (IDEA 11.x ~ Windows 7 ~ Java 7). Specifying the systempath property was referencing the IDEA jre ...

A stable solution was to create a local maven profile under $HOME/.m2/settings.xml

<profiles>
  <profile>
    <id>dev</id>
      <activation>
        <activeByDefault>true</activeByDefault>
          <jdk>NUMERIC_VERSION</jdk>
        </activation>
        <properties>
          <java.home>                   
            <!-- ABSOLUTE_PATH_HERE -->
          </java.home> 
        </properties>
  </profile>
</profiles>
淡淡離愁欲言轉身 2024-10-31 05:10:49

只是为了在有关更改窗口首选项的答案中添加更多信息。我将 JRE 位置设置为 C:\Program Files\Java\jre7 因为这似乎是显而易见的选择。

然而,这是一个失败。所指出的正确答案是C:\Program Files\Java\jdk1.7.0_10\jre。我指出这一点是因为这是一个很容易犯的错误。

Just to add a little more information to the answer about changing Window preferences. I had put the JRE location as C:\Program Files\Java\jre7 because this seemed the obvious choice.

However, this is a fail. The correct answer as pointed out is C:\Program Files\Java\jdk1.7.0_10\jre. I'm pointing this out because its an easy mistake to make.

沧桑㈠ 2024-10-31 05:10:49

今天有同样的问题。结果我特别需要在路径中使用“Program Files”,尽管这个 Windows 安装(以及文件夹的名称)是德语的。

这样的事情也不是第一次发生了。

因此,如果您确定您的路径正确,请尝试“程序文件”而不是本地化的替代方案。为我工作。

Had the same issue today. Turns out I specifically needed to use "Program Files" in the path, despite this windows install (and thus the folder's name) being in German.

It's not the first time this sort of thing happened, either.

So if you're sure your paths are correct, try "Program Files" instead of your localized alternative. Worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文