File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes createProcess error=193,  %1 is not a valid win 32 application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "createProcess error=193,  %1 is not a valid win 32 application" Watch "createProcess error=193,  %1 is not a valid win 32 application" New topic
Author

createProcess error=193, %1 is not a valid win 32 application

syed vaseem
Greenhorn

Joined: May 03, 2011
Posts: 6
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......
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

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.

please help me out asap...

Please EaseUp.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Chris Hurst
Ranch Hand

Joined: Oct 26, 2003
Posts: 416
    
    2

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
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

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.
syed vaseem
Greenhorn

Joined: May 03, 2011
Posts: 6
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...

package gui;

import javax.swing.*;
import java.io.File;

public class ExecutableAnalyzer { // this class is used to calculate time and memory of jar and exe files.

public long getRunningTime(String filename) // this function is used to calculate time of a jar and exe files.

{

long startTime,endTime,exetime;

Runtime r = Runtime.getRuntime();

Process p = null;

String command;

File dir = new File("C:\\");

command="java -jar "+filename; // here i want to implement if ststement

startTime=System.currentTimeMillis();

try
{

p = r.exec(command,null,dir);

p.waitFor();

}

catch(Exception e)

{

JOptionPane.showMessageDialog(null,"Error:"+e.getMessage());
}

endTime=System.currentTimeMillis();

exetime=endTime-startTime;

return exetime;

}

public long getMemory(String filename) // this function is used to calculate memory taken by jar and exe files

{

long usedmemory;

Runtime r = Runtime.getRuntime();

Process p = null;

String command;

File dir = new File("C:\\");

command="java -jar "+filename; //here i want to implement if statement

try

{

p = r.exec(command,null,dir);

p.waitFor();

}

catch(Exception e)

{

JOptionPane.showMessageDialog(null,"Error:"+e.getMessage());
}

usedmemory=r.totalMemory()-r.freeMemory();

return usedmemory;

}
}
syed vaseem
Greenhorn

Joined: May 03, 2011
Posts: 6
thank you guys... for helping.. me... my probs are solved related to my project.. thanks to everyone....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: createProcess error=193, %1 is not a valid win 32 application