Jar Up and Run – How to run a class in jar file

Jar Up and Run

Jar Up and Run

Ok not so fast – a brief background first. Have you ever used hudson, is it cool to just run it by typing java -jar hudson.war, well you can do it too, but need to take care of some steps before that, here you go!

1. Cerate your application with all the classes and libraries included, and most importantly ONE MAIN class ( which has a MAIN method ) , lets call it MyDriver.java

2. Now create a test file, input.txt with the following info in it (only one line ), Main-Class: classname In this case it will be Main-Class: MyDriver.java (don’t forget the space after Collen “:” – it wont work otherwise ) – click here for more info and search for “jar”

3. now run this command – jar cfm jar-file manifest-addition input-file(s). In this case it will be jar cfm my.jar input.txt *.* (or *.class what every you want to add ) – click here for details on this command

Finally you have your jar ready to run or rather FLY. you can use this command to do exactly that!

java -jar my.jar    ( this should run what ever you have in your main method in your main class ) - clieck here for details

Leave a comment

Filed under Java

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s