简体   繁体   English

无法通过bat文件运行Java

[英]Unable to run java through bat file

I set my environment variables correct, and while running Java <classname> it is running fine. 我设置了正确的环境变量,并且在运行Java <classname>时运行良好。

But when running the same through a bat file, I'm getting errors like java is not recognized as internal or external command or bat file . 但是,当通过bat文件运行相同文件时,出现诸如java is not recognized as internal or external command or bat file

I tried displaying the path and classpath, but everything is fine there. 我尝试显示路径和类路径,但是在那里一切都很好。 What am I doing wrong? 我究竟做错了什么?

Here is my piece of code: 这是我的代码:

cd\
cd C:\myproject
set PATH="C:\Program Files\Java\jdk1.7.0_51\bin;"%PATH%
set CLASSPATH="C:\myproject\sqljdbc4.jar;C:\myproject\jxl-2.6.12.jar"
java InsertRecords %1 %2
pause

java executable isn't covered in PATH, add it to path 路径未涵盖Java可执行文件,请将其添加到路径

change it to 更改为

set PATH=%PATH%;C:\Program Files\Java\jdk1.7.0_51\bin\

I think the problem is with how you are setting the path variable...take a look at this... 我认为问题在于您如何设置路径变量...看看这个...

"C:\Program Files\Java\jdk1.7.0_51\bin;"
                                      ^---This doesn't look right

Try using something more like... 尝试使用更多类似...

set PATH="C:\Program Files\Java\jdk1.7.0_51\bin";%PATH%
                                               ^--- Note the change here...

PATH变量中的长路径名中不需要引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM