Jar is a collection of files. To make a jar an executable the most important thing is that it should contain a class that has the main() method. So, you can make a jar executable only if contains a .class file that has a main method. That class will look like this.
public class AClass
{
public static void main(String[] args)
{
...
}jar
...
}
Then and only then can you make a jar executable.
If the main() method class is present. Then to make the jar executable do this.
- Extract the jar
- In the manifest file add this line
Main-Class:AClass
and don't forget to press enter
after this line. follow this link
- Rejar the class files. You got the executable jar now
To execute the jar, (suppose you made a.jar executable), then run java -jar a.jar
to run the jar file.
Second thing is that the command that you have posted in the question does not require those jars to be executable. When you use -cp
, then the parameters (i.e. a.jar etc..)are basically libraries or in other words, when java
will look for a class file to find definition of a class or a function or whatever for that matter, it will look inside these jars
if what it is looking for is not part of the java standard library.