在 Windows 7 上使用 BAT 文件设置 java.library.path

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6505573/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 17:13:56  来源:igfitidea点击:

Setting the java.library.path using a BAT file on windows 7

javawindowsbatch-file

提问by KaiserJohaan

I am trying to set the java.library.path to the current directory using a BAT-file.

我正在尝试使用 BAT 文件将 java.library.path 设置为当前目录。

Heres what I use:

这是我使用的:

java -Djava.library.path=%cd%
pause

However it does not work. The command promt just returns this:

但是它不起作用。命令提示符只返回这个:

C:\Users\Johan-bar\Desktop\Arbete>java -Djava.library.path=C:\Users\Johan-bar\De
sktop\Arbete
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)

where options include:
    -client       to select the "client" VM
    -server       to select the "server" VM
    -hotspot      is a synonym for the "client" VM  [deprecated]
                  The default VM is client.

    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A ; separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose[:class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -jre-no-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
    -agentlib:<libname>[=<options>]
                  load native agent library <libname>, e.g. -agentlib:hprof
                    see also, -agentlib:jdwp=help and -agentlib:hprof=help
    -agentpath:<pathname>[=<options>]
                  load native agent library by full pathname
    -javaagent:<jarpath>[=<options>]
                  load Java programming language agent, see java.lang.instrument

    -splash:<imagepath>
                  show splash screen with specified image

C:\Users\Johan-bar\Desktop\Arbete>pause

What have I done wrong?

我做错了什么?

回答by wjans

Your command is not well-formed, as stated by the error-message. Since you are trying to run a jar-file, you should specify it like this:

如错误消息所述,您的命令格式不正确。由于您正在尝试运行 jar 文件,因此您应该像这样指定它:

java [-options] -jar jarfile [args...]

In your case that would be:

在你的情况下,这将是:

java -Djava.library.path=%cd% -jar myJar

Note: The reference to the jarshould contain the extension as well. If your jar is actually called myJar, consider changing it to have the .jarextension. If not, add .jarto above mentioned command.

注意:对 的引用也jar应包含扩展名。如果您的 jar 实际被调用myJar,请考虑将其更改为具有.jar扩展名。如果没有,请添加.jar到上述命令中。

回答by Shervin Asgari

You have probably forgotten the quotes "

你可能忘记了引号 "

Try this:

尝试这个:

java "-Djava.library.path=C:\Users\Johan-bar\Desktop\Arbete"