Error while executing java code in batch script
Here is my batch script to execute a java code-
@echo off
@setlocal
set JARS=log4j.jar;commons-logging-1.0.4.jar
set abc="JAVA_HOME\bin\java" -cp %JARS%; "C:\Documents and settings\Administrator\Desktop开发者_StackOverflow中文版\Temp" Test
echo %abc%
%abc%
And i get this error-
The system cannot find the path specified.
I have copied the compiled class file in the same location. But to be on a safer side i've provided the path of the class file above. Am I going wrong somewhere?
sorry, dont have much time, but dont you want the output of JAVA_HOME?
for that you would use % like:
set x="%JAVA_HOME%\bin\java"
@echo off
@setlocal
set command="%JAVA_HOME%\bin\java" -cp log4j.jar;commons-logging-1.0.4.jar;"C:\Documents and settings\Administrator\Desktop\Temp" Test
echo %command%
%command%
cmd
is a reserved word, you can't use it as a variable like that!- System variables should be
%
'd to be substituted. - Use double quotes for paths containing spaces.
- You can't give the path to a class to run a class. You have to just give the class name.
This worked for me
@echo off
set JAVA_HOME="C:\Program Files\java\jre6"
set JARS=".;C:\Program Files\lib\log4j.jar;C:\Program Files\lib\commons-logging-1.1.1.jar;"
set runJava=%JAVA_HOME%\bin\java -cp %JARS% Test
%runJava%
for starters you need:
set cmd="%JAVA_HOME%\bin\java" -cp "log4j.jar;commons-logging-1.0.4.jar;C:\Documents and settings\Administrator\Desktop\Temp" Test
update:
showed how classname "Test" should be incorporated.
This is an amalgamtaion of the above answers. All are correct is part.
@echo off
set runJava="%JAVA_HOME%\bin\java" -cp log4j.jar;commons-logging-1.0.4.jar "C:\Documents and settings\Administrator\Desktop\Temp\Test.class"
echo %runJava%
%runJava%
精彩评论