Sunday 9 February 2014

How to create library files in java using some other libraries (dependencies)

If you have written some functions and want others to use it. You can create a library file(.jar) and publish it. 

Creating a Library File:

Step 1: Create a Java project.




Step 2: Keep your code ready.(For simplicity, i have taken just one add function but you create your desired functions)



Step 3: export the project(Don't forget to remove .project and .classpath option while exporting)
Go to project explorer> Right Click on your project> Export



Enhancing Library Features:

If you want to use someone else Library and want to publish it by enhancing its feature. In above step, i have created a library with the name kapillib.jar. Now you can enhance the feature of kapillib.jar library and can create your own library yourlib.jar.

Step 1:  Create your project and add jar/library files







Step 2: Enhance the features of library



Step 3: export the project as we did earlier (Don't forget to remove .project and .classpath option while exporting)

Step 4: Merge both the libraries and create one single jar/library file(If you dont want to merge both the libraries then you need to supply both libraries to user)

For merging libraries, use jar splice in two steps. 1. add jars 2. create fat jar

Add both the jars kapillib.jar and yourlib.jar. Click on 4th option of below screen shot to merge both the library and create final.jar.



How to use Library file.

Step 1:  Create your project and add jar/library file (final.jar) as we did in (enhancing library features's step:1)

Step 2:  Use the library and enjoy.




If you find errors in this tutorial, please feel free to contact me at kapil.sharma91812@gmail.com

No comments:

Post a Comment