简体   繁体   中英

Unable to run java through bat file

I set my environment variables correct, and while running Java <classname> it is running fine.

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 .

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

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变量中的长路径名中不需要引号。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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