创建批处理文件以在 Java 中设置路径

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

Creating a Batch File to Set Path in Java

javabatch-file

提问by M.A.Murali

I have installed JDK 1.7.0_17 on my windows7 32 bit machine and created a batch file set java path but it doesn't work.

我已经在我的 windows7 32 位机器上安装了 JDK 1.7.0_17 并创建了一个批处理文件集 java 路径,但它不起作用。

I have installed jdk under c:\program files.... and need to run java from E: and created batch file under E:\ as follows:

我已经在 c:\program files.... 下安装了 jdk 并且需要从 E: 运行 java 并在 E:\ 下创建批处理文件,如下所示:

set path="C:\Program Files\Java\jdk1.7.0_17\bin";

I got the following exception whenever I run the .bat file.

每当我运行 .bat 文件时,我都会遇到以下异常。

PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\

What is the mistake in my code?

我的代码有什么错误?

采纳答案by Endoro

Try this:

试试这个:

  path="C:\Program Files\Java\jdk1.7.0_17\bin";%path%

回答by Gaurav

After this set path="C:\Program Files\Java\jdk1.7.0_17\bin";add pause();

在此之后set path="C:\Program Files\Java\jdk1.7.0_17\bin";添加 pause();

回答by Bhushan Bhangale

You mention some exception but I do not see any exception in your question.

您提到了一些例外,但我在您的问题中没有看到任何例外。

When you execute the batch file then the PATH variable is set/changed only for that command session.

当您执行批处理文件时,仅针对该命令会话设置/更改 PATH 变量。

If you start new command session then you will not see the changed value.

如果您启动新的命令会话,那么您将看不到更改后的值。

What it is that you want to achieve by just setting the PATH?

您想通过设置 PATH 来实现什么?

What ever you want to run using java so all that in one batch file/session or set the PATH environment variable manually before running the java command

您想使用 java 运行什么,以便在一个批处理文件/会话中运行所有这些,或者在运行 java 命令之前手动设置 PATH 环境变量