How I can execute a jar file via java code?
I want to execute a java executable called "Console.jar" by code but I don't know how to do it.
How I can execute a jar file via java code?
I want to execute a java executable called "Console.jar" by code but I don't know how to do it.
A jar is simply a zip with a different extension.
So if you like to see what is present inside a jar simply rename it to .zip and open with your preferred zip client (winzip, winrar, unzip, 7zip...)
If you need to launch an executable jar from command line:
java -jar <jarFileWithJarExtension>
for example
java -jar Console.jar
If you need to launch it from a java application you can do that with the following code:
Runtime.getRuntime().exec("java -jar Console.jar");
If you need also to interact with Console.jar take a look at the class Process
The pro way to do it ProcessBuilder:
//Create a process builder
ProcessBuilder builder = new ProcessBuilder("java", "-jar","path/f.jar", "argument 1","argument 2");
//start it
Process process = builder.start();
So you can have control over the jar you have already opened.You can get it's output,close it,be notified if it crashed etc.