I'm pretty new to programming, so this should be an easy one. I'm switching from eclipse to netbeans and I am trying to add libjinput-osx.jnilib to my working directory. I have step by step instructions for eclipse, but not netbeans. I'm about 2.5 hours and 65 google searches in and I still cant find the answer to these two basic questions I have.

  1. What exactly is a working directory in java?
  2. How do you add a .jnilib file to your working directory in netbeans?

My end goal is to get an xbox controller to control a game of snake I wrote. I am trying to use JInput and this tutorial. In order to compile properly on OSX I need to put libjinput-osx.jnilib in the "working directory".

有帮助吗?

解决方案 2

There are two aspects to this question.

When you run a command from the command line, the "working directory" is the directory you were in when you ran the command. The instructions that you are reading say to put the native library there because Java's default search path for native library includes the current directory. Alternatively, you could add a -Djava.library.path=... option to the java command to set the search path explicitly.

When you run a command from within Eclipse ... or NetBeans ... the IDE's launcher will set the appropriate JVM parameters to include the project's native library directory on the search path. You need to put the library in THAT directory. This wiki page explains what you need to do for NetBeans.

其他提示

The "working directory" is the location where the application is working in...cryptic huh ;)

Typically it's the launch location for the app, although this can be modified through flags and other process.

In Netbeans, the working directory is typically the root directory of the project (which contains the src and nbproject folder), but this can be changed via the project properties.

One of the simplest ways to find the working directory at run time (this is useful for testing) is to do some thing like...

System.out.println(new File(".").getAbsolutePath());

It looks like what you're really trying to do is load a native library. Try this:

public class MainClass {
    static {
        System.loadLibrary( "Your_native_lib_file_name" ); // Note: do not include the file extension!
    }
}

You might also try -Djava.library.path=/exact/path/to/dir/

Answer copied from here: Java can't seem to find my native libraries

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top