本文介绍了Maven:缺少POM.xml中的工件com.sun:tools:jar:1.6.0编译时异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试增加对工具的依赖时,我遇到了一个奇怪的问题,并且在pom.xml中遇到了编译时异常. jar显示如下(缺少工件com.sun:tools:jar:1.6.0 )

I am getting one weird issue and getting a compile time exception in my pom.xml when i am trying to add dependancy for tools. jar displayed as below(Missing artifact com.sun:tools:jar:1.6.0)

我将我的JAVA_HOME变量设置如下:

I have set my JAVA_HOME variable as below:

JAVA_HOME :C:\ Program Files \ Java \ jdk1.6.0_34

JAVA_HOME: C:\Program Files\Java\jdk1.6.0_34

当我将其硬编码到JDK1.6的实际路径时,我没有发现以下任何错误.

When i hardcode it to the actual path of JDK1.6 i dont find any error as below.

 <dependency>
   <groupId>com.sun</groupId>
   <artifactId>tools</artifactId>
   <version>1.6.0</version>
   <scope>system</scope>
   <systemPath>C:\Program Files\Java\jdk1.6.0_34\lib\tools.jar</systemPath>
 </dependency>

但是我知道它不是很好的做法.要求提供指导以解决此错误.

but i know its not good practise. Request guidance in resolving this error.

推荐答案

java.home是一个System属性,通常指向jre目录,并且指向一个不存在的jar时会出现错误.

java.home is a System property which generally points to the jre directory and you are getting an error as you have pointed to a jar which doesn't exist.

如果要在pom文件中引用环境变量,请使用以下语法.

In case you want to refer to an environment variable within your pom file, use the below syntax.

${env.variable_name}

根据您的情况,应为${env.JAVA_HOME},如下所示

In your case, it should be ${env.JAVA_HOME} as seen below

<dependency>
   <groupId>com.sun</groupId>
   <artifactId>tools</artifactId>
   <version>1.6.0</version>
   <scope>system</scope>
   <systemPath>${env.JAVA_HOME}/lib/tools.jar</systemPath>
 </dependency>

更新:正如lexicore所提到的,由于MAC JDK具有不同的文件结构,因此这不适用于MAC.

Update: As lexicore has mentioned, this wont work with MAC as the MAC JDK has a different file structure.

这篇关于Maven:缺少POM.xml中的工件com.sun:tools:jar:1.6.0编译时异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 16:34