12

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".

Preston
  • 3,273
  • 4
  • 26
  • 35

3 Answers3

18

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>
steve_barham
  • 196
  • 1
  • 3
  • 2
    For newer versions this is not true any longer, the second artifact is now called "jna-platform", without a classifier. – David Dec 13 '14 at 21:09
7

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>
Community
  • 1
  • 1
yair
  • 8,945
  • 4
  • 31
  • 50
  • 4
    +1 The artifactId `platform` has changed to `jna-platform` for version 4.0.0. Just something for people to be aware of. – Andrew Mao Sep 26 '13 at 05:11
0

I downloaded the files and placed the in a lib folder in the project root. Seams to work just fine for me. You have to update it manual if they release a new version.

<properties>
    <jna.version>3.4.0</jna.version>
</properties>   

<dependencies>
    <dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>${jna.version}</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/jna.jar</systemPath>
</dependency>
<dependency>
    <groupId>net.java.dev.jna</groupId>
    <artifactId>jna</artifactId>
    <version>${jna.version}</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/platform.jar</systemPath>
    <classifier>platform</classifier>
</dependency>
</dependencies>
Mikael Svensson
  • 692
  • 1
  • 7
  • 20