Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get maven to download the platform.jar from the JNA project

Tags:

maven-2

jna

I have the following POM entry

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>3.3.0</version>
</dependency>

When I build my project it downloads the following files:

  • jna-3.3.0.jar
  • jna-3.3.0.jar.sha1
  • jna-3.3.0.pom
  • jna-3.3.0.jar.sha1

If you visit the repository at http://download.java.net/maven/2/net/java/dev/jna/jna/3.3.0/ you can see there are numerous other files. Why isn't Maven downloading those other files?

If you open the jna-3.3.0.pom you see

<plugins>
  <!-- fake out maven and install the binary artifact -->
  <plugin>
    <groupId>org.jvnet.maven-antrun-extended-plugin</groupId>
    <artifactId>maven-antrun-extended-plugin</artifactId>
    <executions>
      <execution>
        <phase>package</phase>
        <goals>
          <goal>run</goal>
        </goals>
        <configuration>
          <tasks>
            <!--<ant dir="." target="dist" />-->
            <attachArtifact file="dist/jna.jar" />
            <attachArtifact file="dist/platform.jar" classifier="platform" type="jar" />
            <attachArtifact file="dist/src-mvn.zip" classifier="sources" type="jar"/>
          </tasks>
        </configuration>
      </execution>
    </executions>
  </plugin>
</plugins>

I suspect the issue has something to do with the comment in the pom "fake out maven and install the binary artifact".

like image 289
Preston Avatar asked Jun 17 '11 20:06

Preston


2 Answers

If you add a second dependency to your project alongside the existing JNA dependency, with a classifier added, you should get the artifact added to your build.

<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>3.3.0</version>
    <classifier>platform</classifier>
</dependency>

As you now have two artifacts from the same project, it would be sensible to extract the version element into a project level property so that updating it updates both:

<properties>
    <jna.version>3.3.0</jna.version>
</properties>

<dependencies>
    <dependency>
        <groupId>net.java.dev.jna</groupId>
        <artifactId>jna</artifactId>
        <version>${jna.version}</version>
    </dependency>
    <dependency>
        <groupId>net.java.dev.jna</groupId>
        <artifactId>jna</artifactId>
        <version>${jna.version}</version>
        <classifier>platform</classifier>
    </dependency>
</dependencies>
like image 125
steve_barham Avatar answered Nov 08 '22 17:11

steve_barham


I didn't really understand the classifier usage in @steve_barham's answer.

I searched JNA's project in github and found a file called pom-jna-platform.xml, which includes the following artifact details:

<groupId>net.java.dev.jna</groupId>
<artifactId>jna-platform</artifactId>
<version>4.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

So I just used the following for downloading both jna and jna-platform jars:

<properties>
    <jna.version>4.0.0</jna.version>
</properties>

<dependencies>
    <dependency>
        <groupId>net.java.dev.jna</groupId>
        <artifactId>jna</artifactId>
        <version>${jna.version}</version>
    </dependency>
    <dependency>
        <groupId>net.java.dev.jna</groupId>
        <artifactId>jna-platform</artifactId>
        <version>${jna.version}</version>
    </dependency>
</dependencies>
like image 43
yair Avatar answered Nov 08 '22 17:11

yair