How to create an executable helloworld.jar
Let’s say you’re in the final stage for a job.
You’re instructed to create an executable jar file whose main method prints hello, world
following a line separator. And you have 600 seconds to do that.
If you think about ant
, maven
, or gradle
, you’re already late.
edit HelloWorld.java
$ vi HelloWorld.java $ cat HelloWorld.java public class HelloWorld { public static void main(final String... args) { System.out.printf("hello, world%n"); } } $ javac HelloWorld.java java HelloWorld hello, world
edit HelloWorld.mf
$ vi HelloWorld.mf $ cat HelloWorld.mf Main-Class: HelloWorld $
create the jar
$ jar cmf HelloWorld.mf helloworld.jar HelloWorld.class $ java -jar helloworld.jar hello, world $
How fast can you do that?