tags:

views:

374

answers:

2

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>
  ...
+3  A: 
<classpath>
      <pathelement location="path_to_toold_folder/tools.jar"/>
</classpath>

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

Geo
I've already done this for a annotations processing classes. But I need to add tools.jar for dependencies (apt too) that are not inside ant tasks.I need to add tools.jar in the project.xml.
Guillaume
A: 

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>
Guillaume