Reputation: 449
Part of my program will need to execute another java program I wrote as a process, if I write:
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec(<path to class file>);
Why does this not work? The error tells me its not a vlaid win32 application.
Upvotes: 0
Views: 368
Reputation: 6683
Well, it's right: a class file is not a valid Win32 application. You need to execute the class file with the Java runtime:
Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("java [YourClassName]");
This assumes that you have a main
method in your class.
Upvotes: 1
Reputation: 2422
(<path to class file>)
... to the jar? or to the myClass.class?
can you run the class in a console:
java -jar myClass.jar
Upvotes: 0
Reputation: 13123
Well, it doesn't work because it is NOT a win32 application.
Class files are run by the java virtual machine, not by the Windows operating system. You could try feeding the command 'java -jar .jar, once you've packaged your class file and the other class files that it needs in a jar file.
Upvotes: 0