Click here to Skip to main content
15,888,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this command:

java -jar trang.jar 5-something.xml 5.1-somethingElse.xsd

I would like to execute this from Java program.

Desktop.getDesktop().open(new File("trang.jar"));


This line executes the program mas without the arguments is useless. There's any way to do what I need?
Posted
Updated 13-Jun-11 1:32am
v2

The easiest way is to use Runtime.exec() in one of its various flavours. For what you want to do, it will work fine, but Java purists will shudder at the non-portability.
Runtime.exec("java -jar trang.jar 5-something.xml 5.1-somethingElse.xsd");

Cheers,
Peter
If this answers your question, mark it accepted. Vote anyway.
 
Share this answer
 
Comments
Maxdd 7 13-Jun-11 7:33am    
Didn't tested but that should work, thank you very much :)
Maxdd 7 13-Jun-11 9:18am    
I get that error "“Cannot make a static reference to the non-static method” Any idea ?
Maxdd 7 13-Jun-11 9:32am    
Solved with Runtime.getRuntime().exec
Peter_in_2780 13-Jun-11 21:08pm    
oops! Forgot the subtle difference between Runtime (the class) and runtime (the instance) in my code I peeked at.
java [ options ] -jar file.jar [ argument ... ] by looking at the documentation[^].
 
Share this answer
 
Comments
Maxdd 7 13-Jun-11 7:32am    
I know that, it's I forgot to place the "java -jar" in my example but that is kind of obvious. What I want e to place it on the code, instead executing with the command line.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900