Problem executing a batch file in a Java application

I have a batch file called run.bat that includes the following code:

@echo off
REM bat windows script
set CXF_HOME=.\lib\apache-cxf-2.2.7
java -Djava.util.logging.config.file=%CXF_HOME%\logging.properties -jar archiveServer-0.1.jar

When I run this file on the command line, it works fine. However, when I try to execute in a java file with the following statement:

File path = new File("C:/Documents and Settings/Zatko/My Documents/Project-workspace/IUG/external/application/archive");    

Runtime.getRuntime().exec(new String[]{"cmd.exe", "/C", "start", "run.bat"}, new String[]{}, path);

The following error appears in the terminal window:

'java' is not recognized as internal or external command, operable program or batch file.

Where could the error be?

+5
source share
2 answers

Java.exe not found in your PATH.

If you can assume that the JAVA_HOME variable is defined, you can modify the batch file:

%JAVA_HOME%\bin\java -Djava.util.logging.config.file=%CXF_HOME%\logging.properties -jar archiveServer-0.1.jar

The best way to do this would be, at the suggestion of the boss, to set the PATH environment variable so that it contains% JDK_HOME% \ bin

File workingDirectory = new File("C:/Documents and Settings/Zatko/My Documents/Project-workspace/IUG/external/application/archive");    
String javaProgram = System.getProperty("java.home") + "\bin";
String[] command = {"cmd.exe", "/C", "start", "run.bat"};
String[] environment = {"PATH=" + javaProgram};
Process process = Runtime.getRuntime().exec(command, environment, workingDirectory);

, . archive.Server . , .

+2

, JAVA_HOME/bin PATH.

+1

All Articles