Wednesday, June 29, 2011

Creating Jar File Using Netbeans or Eclipse

Hello again


Some time smart programmers feel difficult to operate easy steps.


So I am providing steps to create Jar files using IDEs i.e. Netbeans and Eclipse


For Netbeans


Steps are


         1. On completing your project, right click on the Project Name (you can find it a tree structure of your project and its internal files on left side)
       2. Click on Compile and build option in right click menu
       3. After successful compilation of your project, Move to the NetBeansProjects folder in your My Documents or for Mac user it will be present in User folder
       4. In NetBeansProjects go to your Project name folder 
       5. In your Project folder you will find "dist" folder
       6. There you have your Jar file with lib if you used any external APIs
7. Congrats you created your JAR file :)


        NOTE: You can change the name of Jar file and if you want to edit your project after editing repeat this process to obtain modified Jar

For Eclipse 

Steps are

1. Open your project, Click on File (Menu Bar)
2. Select Export and Export dialog box is displayed
3. Under Java, select JAR File and Click Next
4. You will find a box on left top which states "Select the resources to export"
5. In that box check your entire project (Your choose some part of your project for testing your project module)
6. At the bottom you will find an option to choose the path where the JAR file will be exported, provide with your desired path
7. Click next, no necessary change is required in this page, So click again Next 
8. You will be directed to last page, at the bottom there you can choose the class file which is your project's entry point select the appropriate entry class from the project
9. Click on finish, Congrats your JAR file is created :)

Thats it for this post
Enjoy
Keep smiling
Have fun 






For Any Query mail me: ravjot.singh.28@gmail.com

Tuesday, June 28, 2011

Creating Jar file Using CMD/Terminal

Hello Friends :)


Well i will not provide u the basics of Java coz we all are smart programmers, I will touch areas which are essential for programming but at the same time we don't have sufficient resources to get solution.


My First topic will be to create a jar File


How to create a Jar file? ( very common question )


Well many of us use IDEs (Netbeans or eclipse) to create jar files which is the easiest method.


But there are various tricks in which we have to create jar files manually ( these tricks will be provided in future posts NOT TO WORRY :) ) & for starters this is the best place to learn to create jar files using cmd/terminal 

Steps are as follows

1. Make a folder and in that folder compile your .java files. [let the folder location be C:/../Desktop/x]

2. Now after successful compiling the .java files open your notepad and type in it

Main-Class: <your .java file name which u want to run when you run jar file> <Note:press enter after this line>

[optional] Class-Path: <if you are using any library write them here and separate file name with space> <Note:press enter after this line>


  
Eg:  Suppose my main java file name is “main.java” and i am using three libraries “c.jar lib/a.jar lib/b.jar” . So my notepad will contain

Main-Class: main    <Note:press enter after this line>

Class-Path: lib/a.jar lib/b.jar c.jar <Note:press enter after this line>

Save as the file “main.mf” at the location “C:/../Desktop/x/main.mf”

3.  Now open your cmd/terminal and type in it cd C:/../Desktop/x press enter

4. Now type the command “jar cvfm <your jar file name>.jar main.mf *.class” and press enter

5. Thats it in 4 steps you created your jar file congrats to all :)


Thats it for this post
Enjoy
Keep smiling
Have fun 





For Any Query mail me: ravjot.singh.28@gmail.com