1

I have a project that uses some legacy script for processing the source code. I cannot get rid of it, so I want to call it from maven.

the problem is that I need to pass as an argument the location of a jar file. I have listed this jar file as a dependency in my pom.xml. is there a way that I can pass the absolute location of the jar file to this script?

santiagozky
  • 2,519
  • 22
  • 31

2 Answers2

1

This isn't by any means ideal, but you could call your script from maven, and pass this in as a parameter:

${settings.localRepository}/<path to artifact>

where path to artifact is a path made up of the group id and artifact id you want. Example, if you wanted a reference to the maven-jar-plugin version 2.2, you'd use this:

${settings.localRepository}/org/apache/maven/plugins/maven-jar-plugin/2.2/maven-jar-plugin-2.2.jar
Michael
  • 6,141
  • 2
  • 20
  • 21
  • Yeah, what you're doing is really unconventional, so this isn't ideal at all. The better plan would be to mavenize those legacy scripts so you no longer need them ;) – Michael Mar 08 '12 at 13:09
0

I like Pascal Thivent's answer to a similar question better. You can refer to dependencies with the ${maven.dependency.junit.junit.jar.path} notation. Pascal includes a sample pom in his answer:

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.stackoverflow</groupId>
  <artifactId>q2359872</artifactId>
  <version>1.0-SNAPSHOT</version>
  <name>q2359872</name>
  <properties>
    <my.lib>${maven.dependency.junit.junit.jar.path}</my.lib>
  </properties>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <phase>process-resources</phase>
            <configuration>
              <tasks>
                <echo>${my.lib}</echo>
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
Community
  • 1
  • 1
piepera
  • 2,033
  • 1
  • 20
  • 21