Hello Olivier,
If your project has a dependency on tools.jar, the artifact presumably need
that dependency to work.
Since the dependency is system scoped, Maven will not download it but look
it up locally.
Therefore, in case someone uses a JDK with different layout than your own,
the dependency will not work.
In the aspectJ-maven-plugin project, we have solved parts of this in the
manner shown in the code snippet below.
Basically, I think that we need a central solution to handle the tools.jar
dependency in maven, since this is
something which needs managing in multiple places - and people will wind up
in the same problem over and over.
So ... My recommendation: define a property for the path to tools.jar.
Define a set of profiles with the different known
locations for tools.jar - each defining the property if the tools.jar file
is found. In case the tools.jar is located in a
different location than your profiles have covered, the user must provide
the path within a -Dtoolsjar=[path] property:
<profiles>
<!--
The AspectJ compilation requires that tools.jar (or its equivalent
for some JDKs) is found on the classpath.
The profiles named [something]toolsJar-profile define the systemPath
for the tools.jar dependency.
-->
<profile>
<id>standardToolsJar-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
<file>
<exists>${java.home}/../lib/tools.jar</exists>
</file>
</activation>
<properties>
<toolsjarSystemPath>${java.home}/../lib/tools.jar</toolsjarSystemPath>
</properties>
</profile>
<profile>
<id>appleJdkToolsJar-profile</id>
<activation>
<activeByDefault>false</activeByDefault>
<file>
<exists>${java.home}/../Classes/classes.jar</exists>
</file>
</activation>
<properties>
<toolsjarSystemPath>${java.home}/../Classes/classes.jar</toolsjarSystemPath>
</properties>
</profile>
.. and then, the dependency (management) section:
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>${java.version}</version>
<scope>system</scope>
<systemPath>${toolsjarSystemPath}</systemPath>
</dependency>
Fair?
2013/8/20 Olivier Lamy <[email protected]>
> Hi,
> I have an issue I don't know how to fix :-(
>
> The goal is to have a dependency on tools.jar.
> This activated by a profile
>
> <profile>
> <id>tools.jar</id>
> <activation>
> <file>
> <exists>${java.home}/../lib/tools.jar</exists>
> </file>
> </activation>
> <dependencies>
> <dependency>
> <groupId>openjdk</groupId>
> <artifactId>tools</artifactId>
> <version>1.6</version>
> <scope>system</scope>
> <systemPath>${java.home}/../lib/tools.jar</systemPath>
> </dependency>
> </dependencies>
> </profile>
>
> So all is fine at this point.
>
> But now the installed/deployed pom add this dependency in the
> dependencies section.
> That's something I definitely don't want because the ${java.home} is
> interpolated so except everybody use the same as me that won't work
> and furthermore I don't need it for using this library.
>
> Any idea?
>
> Thanks
> --
> Olivier Lamy
> Ecetera: http://ecetera.com.au
> http://twitter.com/olamy | http://linkedin.com/in/olamy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
>
--
--
+==============================+
| Bästa hälsningar,
| [sw. "Best regards"]
|
| Lennart Jörelid
| EAI Architect & Integrator
|
| jGuru Europe AB
| Mölnlycke - Kista
|
| Email: [email protected]
| URL: www.jguru.se
| Phone
| (skype): jgurueurope
| (intl): +46 708 507 603
| (domestic): 0708 - 507 603
+==============================+