JInput - Setting up w/ Maven

I’d like to use the JInput libraries in a project of mine but I’m having a difficult time. Most of the links I find for JInput (including links in their Git README) are broken. I figured the best way would be to simply use Maven and pull down the dependencies. I’m using this POM file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.mycompany</groupId>
    <artifactId>controller</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>net.java.jinput</groupId>
            <artifactId>jinput-platform</artifactId>
            <version>2.0.6</version>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>net.java.jutils</groupId>
            <artifactId>jutils</artifactId>
            <version>1.0.0</version>
        </dependency>
        <dependency>
            <groupId>net.java.jinput</groupId>
            <artifactId>jinput-platform</artifactId>
            <version>2.0.6</version>
            <classifier>natives-windows</classifier>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>net.java.jinput</groupId>
            <artifactId>jinput-platform</artifactId>
            <version>2.0.6</version>
            <classifier>natives-linux</classifier>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>net.java.jinput</groupId>
            <artifactId>jinput-platform</artifactId>
            <version>2.0.6</version>
            <classifier>natives-osx</classifier>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>net.java.jinput</groupId>
            <artifactId>jinput</artifactId>
            <version>2.0.6</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
    </properties>
</project>

When I try to run ControllerReadTest from their Git repository I get this error:

--- exec-maven-plugin:1.2.1:exec (default-cli) @ controller ---
java.lang.UnsatisfiedLinkError: no jinput-dx8_64 in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
	at java.lang.Runtime.loadLibrary0(Runtime.java:870)
	at java.lang.System.loadLibrary(System.java:1119)
	at net.java.games.input.DirectInputEnvironmentPlugin$1.run(DirectInputEnvironmentPlugin.java:75)
	at java.security.AccessController.doPrivileged(Native Method)
	at net.java.games.input.DirectInputEnvironmentPlugin.loadLibrary(DirectInputEnvironmentPlugin.java:67)
	at net.java.games.input.DirectInputEnvironmentPlugin.<clinit>(DirectInputEnvironmentPlugin.java:109)
	at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init>(DirectAndRawInputEnvironmentPlugin.java:45)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
	at java.lang.Class.newInstance(Class.java:438)
	at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:160)
	at com.mycompany.controller.ControllerReadTest.<init>(ControllerReadTest.java:253)
	at com.mycompany.controller.ControllerReadTest.main(ControllerReadTest.java:302)
java.lang.UnsatisfiedLinkError: no jinput-raw_64 in java.library.path
	at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1857)
	at java.lang.Runtime.loadLibrary0(Runtime.java:870)
	at java.lang.System.loadLibrary(System.java:1119)
	at net.java.games.input.RawInputEnvironmentPlugin$1.run(RawInputEnvironmentPlugin.java:75)
	at java.security.AccessController.doPrivileged(Native Method)
	at net.java.games.input.RawInputEnvironmentPlugin.loadLibrary(RawInputEnvironmentPlugin.java:67)
	at net.java.games.input.RawInputEnvironmentPlugin.<clinit>(RawInputEnvironmentPlugin.java:109)
	at net.java.games.input.DirectAndRawInputEnvironmentPlugin.<init>(DirectAndRawInputEnvironmentPlugin.java:46)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
	at java.lang.Class.newInstance(Class.java:438)
	at net.java.games.input.DefaultControllerEnvironment.getControllers(DefaultControllerEnvironment.java:160)
	at com.mycompany.controller.ControllerReadTest.<init>(ControllerReadTest.java:253)
	at com.mycompany.controller.ControllerReadTest.main(ControllerReadTest.java:302)
Sep 16, 2015 3:58:44 PM net.java.games.input.ControllerEnvironment log
INFO: net.java.games.input.DirectAndRawInputEnvironmentPlugin is not supported

It seems to me it can’t find the dll files which are under Runtime Dependencies. I’m not sure what I’m missing in the POM. Any ideas?

Edit: I was able to get it working the old fashioned way by extracting the jars from Maven and putting the ddls in my library path. I’m using Maven for my other dependencies so I’d prefer to be consistent so if anyone knows how to get it working 100% Maven, please let me know.

Have you tried mavennatives?

you can unpack them manually.

[#] look into your local maven repository under net\java\jinput\jinput-platform\2.0.6 if you use 2.0.6.
[#] open it (jinput-platform-2.0.6-natives-windows.jar) with 7z or something else,
[#] drop the files into the [icode]java.library.path[/icode] folder.
[#] win

or you can unpack them with the [icode]maven-dependency-plugin[/icode] plugin :

<dependencies>
  <dependency>
    <groupId>net.java.jinput</groupId>
    <artifactId>jinput</artifactId>
    <version>2.0.6</version>
  </dependency>
</dependencies>

dependency:tree should look like this :

[INFO] +- net.java.jinput:jinput:jar:2.0.6:compile
[INFO] |  +- net.java.jutils:jutils:jar:1.0.0:compile
[INFO] |  +- net.java.jinput:jinput-platform:jar:natives-linux:2.0.6:runtime
[INFO] |  +- net.java.jinput:jinput-platform:jar:natives-windows:2.0.6:runtime
[INFO] |  \- net.java.jinput:jinput-platform:jar:natives-osx:2.0.6:runtime

use maven-dependency-plugin like :

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-dependency-plugin</artifactId>
      <version>2.8</version>
      <executions>
    
        <execution>
          <id>unpack jinput windows</id>
          <phase>compile</phase>
          <goals>
            <goal>unpack</goal>
          </goals>
          <configuration>
            <skip>false</skip>
            <artifactItems>
              <artifactItem>
                <groupId>net.java.jinput</groupId>
                <artifactId>jinput-platform</artifactId>
                <version>2.0.6</version>
                <classifier>natives-windows</classifier>
                <type>jar</type>
                <overWrite>true</overWrite>

                <outputDirectory>${project.build.directory}/unpack</outputDirectory>
                <!-- or somewhere else -->

                <includes>**/*.dll</includes>
              </artifactItem>
            </artifactItems>
          </configuration>
        </execution>
        <execution>
          <id>unpack jinput linux</id>
          <phase>compile</phase>
          <goals>
            <goal>unpack</goal>
          </goals>
          <configuration>
            <skip>false</skip>
            <artifactItems>
              <artifactItem>
                <groupId>net.java.jinput</groupId>
                <artifactId>jinput-platform</artifactId>
                <version>2.0.6</version>
                <classifier>natives-linux</classifier>
                <type>jar</type>
                <overWrite>true</overWrite>
                <outputDirectory>${project.build.directory}/unpack</outputDirectory>
                <includes>**/*.so</includes>
              </artifactItem>
            </artifactItems>
          </configuration>
        </execution>
        <execution>
          <id>unpack jinput osx</id>
          <phase>compile</phase>
          <goals>
            <goal>unpack</goal>
          </goals>
          <configuration>
            <skip>false</skip>
            <artifactItems>
              <artifactItem>
                <groupId>net.java.jinput</groupId>
                <artifactId>jinput-platform</artifactId>
                <version>2.0.6</version>
                <classifier>natives-osx</classifier>
                <type>jar</type>
                <overWrite>true</overWrite>
                <outputDirectory>${project.build.directory}/unpack</outputDirectory>
                <includes>**/*.dylib,**/*.jnilib</includes>
              </artifactItem>
            </artifactItems>
          </configuration>
        </execution>
    
      </executions>
    </plugin>
  </plugins>
</build>

you might want to use another phase and maybe use a few [icode][/icode] to use it with a specific profile ([icode]false[/icode]).

o/