Error:Cannot run program "C:\Users\x\Desktop\jannotatix.jar" (in directory "C:\Users\x\Desktop"); createProcess error=193, %1 is not a valid win32 application.
This above error i am getting when i select a jar file from the path mentioned above but it's working fine with exe files, i am able to execute successfully exe files but when i try to do for jar files the above mentioned error i get... please help me out asap. This is my part of project which is used to calculate time n memory used to execute an exe file and jar file.
Here goes the code....
please help me out asap... it's working fine with .exe files but for jar files it shows the error which i mentioned above in starting......
Could you please UseCodeTags next time? That makes it easier to read your code.
syed vazzz wrote:Error:Cannot run program "C:\Users\x\Desktop\jannotatix.jar" (in directory "C:\Users\x\Desktop"); createProcess error=193, %1 is not a valid win32 application.
That's because a JAR is not an executable file like .exe files are. JAR files are executed using the javaw.exe tool. So you would need to execute the following command:
"javaw -jar \"C:\\Users\\x\\Desktop\\jannotatix.jar\"". I added quotes around the JAR path to make sure it also works when you use a path with spaces in it. You can also use a String to execute, in which case these extra quotes are no longer necessary:
I also suggest you read When Runtime.exec() won't.
If your lazy you could make the Jar executable ensure the file type jar in Windows Explorer is associated with Java and provided your Manifest in your jar has the correct main class specified it should work. I'd suggest the "jawaw" , "-jar" way is better but I'd have probably been lazy and tested the other way first ;-)
"Eagles may soar but weasels don't get sucked into jet engines" SCJP 1.6, SCWCD 1.4, SCJD 1.5,SCBCD 5
Even if it's an executable JAR, you still need javaw. It's a Windows file association that allows you to double click a JAR file to have it executed. Windows sees that the default action for JAR files is to open it with javaw, and does so.
Joined: May 03, 2011
First of all i want to thanks for everyone who helped me on this post, now i can execute jar files successfully as shown below in the code to check how much time and memory is taken when a jar file is executed, if i want to run .exe files using the code shown below i just need to replace command=filename but i want to implement IF statement in this code like if i select jar file it should execute command="java -jar"+filename or else command=filename to execute .exe files. so please help me out for implementing IF statement in this code so i can recognize whether it is jar or exe file in IF statement somehow. please this is my last step to complete my project.. please friends help me out.....
here goes the code...