I have created a batch file which executes a jar file with a properties file:
@echo off REM Windows bat script java -Xmx256M -Djava.util.logging.config.file=log.properties -jar Archive.jar
I would like to create a Java application that inclu开发者_开发技巧des a code that execute this batch file (feasible) but without showing the DOS window of the executing process. Also, when the application ends the process of this process should terminate too. Is this feasible? Thanks in advance!
you can use javaw.exe instead of java.exe: there will be no console window: http://download.oracle.com/javase/1.4.2/docs/tooldocs/windows/java.html
Using the Java's Runtime
class should work for you:
Runtime runtime = Runtime.getRuntime();
runtime.exec("/somepath/script.bat");
More complex methods are available as well, e.g. for submitting environment variables. You can also use the ProcessBuilder available since JavaSE 1.5. It provides a number of features not available in Runtime
like output redirects.
精彩评论