Instead from command prompt, I am trying to execute java commands like 'javac', 'java' using java program. I have tried Runtime.getRuntime().exec() but it only executes the DOS commands like 'del'. samples those i tried are:
But none of above is working...no error/exception occurs but nothing happen. Just command prompt comes and disappears but no other action is happening....only DOS command such as following 'del' is working:
Read the Javaworld article "When Runtime().exec won't". You really should.
If you don't need the command window, you can simply skip the "cmd" part and execute the javac command directly:
About creating the JAR file, I wouldn't do that using command line but using the API itself. Check out the java.util.jar package; you can use a JarOutputStream around a FileOutputStream to write the entries. Writing an entry goes as follows:
1) create a ZipEntry 2) call putNextEntry()
3) write the entire contents of the file to put in the JAR file
4) repeat steps 2 and 3 for all other entries
5) close() the JarOutputStream You can even add a Manifest.MF file using the Manifest class.
Please search this website; there have been threads about using DOS commands with Runtime.exec() before, but you may have to go back a few years. Some of those commands are specific commands for the command line program, rather than invocations of executables. I can't remember the details, but there will be more in the old thread.