Java + Maven1.x : how to add sun's tools.jar?

2019-08-04 06:06发布

问题:

I must add tools.jar into my maven1 build config but I can't find any help.

Here is the solution I've found using the helpfull sugestion of geo:

I have modified the maven.xml build in order to add the tools.jar in the classpath. A pre-goal before java:compile does the stuff:

<preGoal name="java:compile">
    <ant:path id="tools">
        <ant:pathelement path="${tools.jar}"/>
    </ant:path>
    <maven:addPath id="maven.dependency.classpath" refid="tools"/>
</preGoal>

Below are result of my investiqgations and can be helpfull for someone trying to achieve the same unsing maven 2.x

How do I include tools.jar in my dependencies?

The following code includes tools.jar for JDKs on Windows, Linux and Solaris (it is already included in the runtime for Mac OS X and some free JDKs).

  ...
  <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.4.2</version>
          <scope>system</scope>
          <systemPath>${java.home}/../lib/tools.jar</systemPath>
        </dependency>
      </dependencies>
    </profile>
  </profiles>
  ...

回答1:

<classpath>
      <pathelement location="path_to_toold_folder/tools.jar"/>
</classpath>

Should do the trick.This only works in an ant task.



回答2:

Thanks to Geo, I have modified the maven.xml build in order to add the tools.jar in the classpath.

A pre-goal before java:compile does the stuff:

<preGoal name="java:compile">
    <ant:path id="tools">
        <ant:pathelement path="${tools.jar}"/>
    </ant:path>
    <maven:addPath id="maven.dependency.classpath" refid="tools"/>
</preGoal>


标签: java maven-1