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

蓝咒 提交于 2019-12-11 06:48:24

问题


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>


来源:https://stackoverflow.com/questions/2149633/java-maven1-x-how-to-add-suns-tools-jar

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!