如何为JVM设置PATH环境变量 [英] How to set the PATH environment variable for JVM

查看:969
本文介绍了如何为JVM设置PATH环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行使用Java 7 ProcessBuilder安装在系统上的可执行文件.我注意到环境变量PATH可以通过

I am trying to run executables which are installed on my system with the Java 7 ProcessBuilder. I noticed that the environment variable PATH, which is available via

 System.getenv("PATH");

不包括我自己的自定义设置路径.它返回以下内容:

does not include my own, custom set path. It returns this:

 /usr/bin:/bin:/usr/sbin:/sbin

我的路径如下:

 /Users/saschaf/.bin:/Users/saschaf/Entwicklung/spring-roo-1.2.4.RELEASE/bin:/usr/local/opt/ruby/bin:/usr/local/bin:/Users/saschaf/Entwicklung/android-sdk-macosx/tools:/Users/saschaf/Entwicklung/android-sdk-macosx/platform-tools:/usr/local/share/npm/bin:/Users/saschaf/node_modules/.bin:/Users/saschaf/Entwicklung/git/tools:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

我不知道如何设置PATH变量,以便JVM使用正确的变量.这是什么问题?

I don't know how to set the PATH variable so that the JVM uses the correct one. Whats the problem here?

我正在运行最新的OS X Mavericks,JDK 1.7.0_25-b15,Maven Apache Maven 3.1.1.

I am running the latest OS X Mavericks, JDK 1.7.0_25-b15, Maven Apache Maven 3.1.1.

推荐答案

直接从您可以在不设置PATH变量的情况下很好地运行JDK,或者可以选择方便地设置它.但是,如果希望能够从任何目录运行可执行文件(javac,java,javadoc等),而不必键入命令的完整路径,则应该设置路径变量.如果未设置PATH变量,则每次运行时都需要指定可执行文件的完整路径,例如:

You can run the JDK just fine without setting the PATH variable, or you can optionally set it as a convenience. However, you should set the path variable if you want to be able to run the executables (javac, java, javadoc, and so on) from any directory without having to type the full path of the command. If you do not set the PATH variable, you need to specify the full path to the executable every time you run it, such as:

% /usr/local/jdk1.7.0/bin/javac MyClass.java

要确定路径是否正确设置,请执行:

To find out if the path is properly set, execute:

% java -version

这将打印Java工具的版本(如果可以找到的话).如果版本较旧,或者出现错误Java:找不到命令,则说明路径设置不正确.

This will print the version of the java tool, if it can find it. If the version is old or you get the error java: Command not found, then the path is not properly set.

要永久设置路径,请在启动文件中设置路径.

To set the path permanently, set the path in your startup file.

对于C shell(csh),编辑启动文件(〜/.cshrc):

For C shell (csh), edit the startup file (~/.cshrc):

set path=(/usr/local/jdk1.7.0/bin )

对于bash,请编辑启动文件(〜/.bashrc):

For bash, edit the startup file (~/.bashrc):

PATH=/usr/local/jdk1.7.0/bin:
export PATH

对于ksh,启动文件由环境变量ENV命名.设置路径:

For ksh, the startup file is named by the environment variable, ENV. To set the path:

PATH=/usr/local/jdk1.7.0/bin:
export PATH

对于sh,编辑配置文件(〜/.profile):

For sh, edit the profile file (~/.profile):

PATH=/usr/local/jdk1.7.0/bin:
export PATH

然后加载启动文件,并通过重复java命令来验证路径是否已设置:

Then load the startup file and verify that the path is set by repeating the java command:

这篇关于如何为JVM设置PATH环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆