Java 工作目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13695718/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java Working Directory
提问by spuder
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.
我对编程很陌生,所以这应该很容易。我正在从 eclipse 切换到 netbeans,并且正在尝试将 libjinput-osx.jnilib 添加到我的工作目录中。我有 eclipse 的分步说明,但没有 netbeans。我大约 2.5 小时和 65 次谷歌搜索,但我仍然无法找到这两个基本问题的答案。
- What exactly is a working directoryin java?
- How do you add a .jnilib file to your working directory in netbeans?
- java中的工作目录究竟是什么?
- 如何将 .jnilib 文件添加到 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".
我的最终目标是让一个 Xbox 控制器来控制我写的蛇游戏。我正在尝试使用 JInput 和本教程。为了在 OSX 上正确编译,我需要将 libjinput-osx.jnilib 放在“工作目录”中。
回答by MadProgrammer
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.
在 Netbeans 中,工作目录通常是项目的根目录(其中包含src
和nbproject
文件夹),但这可以通过项目属性进行更改。
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());
回答by Stephen C
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.
当您从命令行运行命令时,“工作目录”是您运行该命令时所在的目录。您正在阅读的说明说要将本机库放在那里,因为 Java 对本机库的默认搜索路径包括当前目录。或者,您可以-Djava.library.path=...
向java
命令添加一个选项以明确设置搜索路径。
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 pageexplains what you need to do for NetBeans.
当您从 Eclipse 或 NetBeans 中运行命令时,IDE 的启动器将设置适当的 JVM 参数以在搜索路径中包含项目的本机库目录。您需要将库放在那个目录中。 此 wiki 页面解释了您需要为 NetBeans 做什么。
回答by ccleve
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/
您也可以尝试 -Djava.library.path=/exact/path/to/dir/
Answer copied from here: Java can't seem to find my native libraries
从这里复制的答案: Java 似乎无法找到我的本机库