JInput “no jinput-dx8 in java.library.path” Error

2019-07-25 14:33发布

问题:

Hi I'm trying to make a game in java that gives users the option to a joystick or gamepad to control movement. So I found something called "JInput" that is suppose to make it easy to detect all connected game controllers. The problem is that when I run it in Eclipse I get the following error: "java.lang.UnsatisfiedLinkError: no jinput-dx8 in java.library.path".

My code is the following:

import net.java.games.input.*;


public class ListControllers 
{

  public static void main(String[] args) 
  {

    System.out.println("JInput version: " + Version.getVersion());

    ControllerEnvironment ce =
         ControllerEnvironment.getDefaultEnvironment();

    Controller[] cs = ce.getControllers();

    if (cs.length == 0) {
      System.out.println("No controllers found");
      System.exit(0);
    }

    // print the name and type for each controller
    for (int i = 0; i < cs.length; i++)
      System.out.println(i + ". " +
             cs[i].getName() + ", " + cs[i].getType() );

  } // end of main()


} // end of ListControllers class

I'm currently developing in Windows 7 environment. Any help would be really appreciated.

回答1:

You should set java.library.path property to point to the directory containing native dlls of JInput. You can do it by adding -Djava.library.path=x (where x is your path) to the command line or to the "VM arguments" field of "Run configurations" dialog in Eclipse.



标签: java jinput