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?

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s