Build error: missing artifact com.sun:tools:jar:1.

2019-02-12 04:36发布

Trying to build PlayN sample projects I get:

Missing artifact com.sun:tools:jar:1.6  pom.xml /playn-cute line 6  Maven Dependency Problem

On every pom.xml file. How do I resolve it?

Edit:

I've added the profiles node to the pom.xml, but the error remains. I've checked the tools.jar is actually exists, and it didn't. So I've added tools.jar to lib folder. And still the error remains.

The full pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
        <groupId>com.googlecode.playn</groupId>
        <artifactId>playn-project</artifactId>
        <version>1.0.1</version>
    </parent>

    <artifactId>playn-cute</artifactId>
    <name>PlayN Cute Metaproject</name>
    <version>1.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <properties>
        <playn.version>1.0.1</playn.version>
    </properties>

    <modules>
        <module>core</module>
        <module>java</module>
        <module>html</module>
        <!-- <module>flash</module> -->
        <module>android</module>
    </modules>

    <profiles>
        <profile>
            <id>default-tools.jar</id>
            <activation>
                <property>
                    <name>java.vendor</name>
                    <value>Sun Microsystems Inc.</value>
                </property>
            </activation>
            <dependencies>
                <dependency>
                    <groupId>com.sun</groupId>
                    <artifactId>tools</artifactId>
                    <version>1.6</version>
                    <scope>system</scope>
                    <systemPath>${java.home}/../lib/tools.jar</systemPath>
                </dependency>
            </dependencies>
        </profile>
    </profiles>
</project>

标签: java maven playn
13条回答
何必那么认真
2楼-- · 2019-02-12 05:00

There are many reasons you might see this error on your eclipse IDE

  1. Eclipse pointing to JRE rather than JDK
  2. JDK library not containing tools.jar

For this you might want to add tools.jar by yourself through Preferences -> Java -> Installed JRE -> (select JDK, edit and add external jars -> navigate to tools.jar)

  1. Other reason might be this -> the parent maven repository of your project have a jar with the same name under some other artifactory.

You need to locate tools.jar through -> Dependency Heirarchy view for pom.xml in eclipse and once you have located the jar you can add an exclusion there

like ->

<groupId>com.parent.project</groupId>
    <artifactId>parent-project-dependencies-pom</artifactId>
    <version>${dependencies.version}</version>
        <exclusions>
            <exclusion>
                <groupId>com.sun</groupId>
                <artifactId>tools</artifactId>
            </exclusion>
         </exclusions>
查看更多
够拽才男人
3楼-- · 2019-02-12 05:00

Some pointers that can help you:

  1. Check if the tools.jar is present in the repo url in pom.xml.
  2. Verify the dependency in pom.xml. It might be incorrect. I did not find any jar artifact at http://search.maven.org/#browse%7C96611365.

Thanks.

查看更多
Root(大扎)
4楼-- · 2019-02-12 05:04

I had the same problem, it was because of multiple tools.jar files in the path.

But the problem was specific to work-space pom dependency. I came to know this, as my other work-spaces in the same eclipse are working fine.

Steps I have taken to investigate & solve:

1) Open project pom file

2) Go the Dependency Hierarchies section in pom

3) In the upper right corner filter text box, enter the name tools.jar

4) This will show the dependency hierarchy of the tools.jar file.

5) In the right hand side Resolved Section, select the tools.jar file and right click on the jar file.

6) select the exclusion of the file.

Then rebuild the project.

查看更多
闹够了就滚
5楼-- · 2019-02-12 05:06

I had to change what you had:

<systemPath>${java.home}/../lib/tools.jar</systemPath>

to the explicit path, using the JDK not the JRE like bmargulies said:

 <systemPath>C:/Program Files/Java/jdk1.6.0_24/lib/tools.jar</systemPath>

Hope that helps.

查看更多
\"骚年 ilove
6楼-- · 2019-02-12 05:10

this is how I resolved it. please paste below lines into your eclipse.ini file.

-vm path till java.exe (as shown below)

-vm C:/Program Files/Java/jdk1.7.0_60/bin/java

hope it helps.

查看更多
Luminary・发光体
7楼-- · 2019-02-12 05:16

You shouldn't need to add the dependency to your POM. I had this problem in eclipse and it was because eclipse was running in a JRE, not a JDK.

See this question here for the same issue: Missing artifact com.sun:tools:jar

Resolved by specifing the vm eclipse uses. Also check the build path for your eclipse project is using a JDK, not a JRE.

Having a JDK on the build path, and explictly setting a JDK in the eclipse INI still doesn't work however if the java on the path was a jre not a jdk (windows path, or linux/mac equivilent).

Run this from the command line to see what java on your path is: How do I find where JDK is installed on my windows machine?

If its a JRE you should change it to a JDK and relaunch your IDE.

查看更多
登录 后发表回答