Pages

Monday, June 2, 2014

Creating a jar file through command prompt

It gives me a feeling like I am interacting more with my computer than usual. I feel like those so called geek hackers in Action movies as I don’t see anything visually until I clean, compile and run my jar files lol. I know I am exaggerating stuffs here, but, its’ sometimes good to enjoy the little things in life you know J

 

Coming to the point, In order to create a file entirely through command prompt, one can possibly follow the forth coming steps to do it.

 

1.       Get to your project folder. In my case it was through

>>cd “projectFolderPath”

 

2.       Create your class file. I created one to print a statement as follows

 

package com.self.jarTest;

 

public class HelloWorld {

    public static void main(String[] args) {

        System.out.println("Hello World");

    }

}

 

3.       Create a build directory

>>md build\classes

 

4.       Psst. I don’t have admin rights on this stupid machine and so I can’t change my environment variables. So I did the following

>>"C:\program files\Java\jdk1.7.0_55\bin\javac.exe” –sourcepath src –d build\classes src\com\self\jarTest\HelloWorld.java

 

In your case, if your environment variables are set properly I assume it must be something similar to

>>javac –sourcepath src –d build\classes (path to your HelloWorld.java file)

 

5.       Now create a folder to put your jar file

>>md build\jar

 

6.       And finally create your jar file (* following line does include a ‘dot’ – ‘.’ – don’t omit it)

>>jar cfm build\jar\HelloWorld.jar mf –C build\classes .

 

@*%%*, My class path is not set properly and I can do nothing about it L So I did the following

>>"C:\program files\Java\jdk1.7.0_55\bin\jar.exe" cfm build\jar\HelloWorld.jar mf –C build\classes .

 

Vola, my jar file is created. Now to do the most meaning full stuff, I am speaking about the “Check if its working or not” theorem. I used the following line of command

>>java -jar "build\jar\HelloWorld.jar"

 

Wohooo…. It worked like charm. I got the following

>>Hello World

 

I know it seems like, I am getting exited for nothing. Who gives a damn J

No comments:

Post a Comment