Actually I am gonna demonstrate the simple way to create the jar file which is a combination of multiple jars’ .
Requirements:

  • Firstly We need the NetBeans
  • JDK 1.6

Here we’ll create a sample Project which is included in NetBeans.

I used NetBeans 6.7.1 and now i am starting my demonstration.

(Also you can create a project where there is presence of jar files)

Let’s make a project File>New Project> …. and as your requirement you can make a project but there

is need of some extra jar files . If you are not familiar with adding jar files to Projects then ,

Please refer this:

Now you are able to attach jar files in Project.

It’s time time to have some trick now, just choose Files Tab in Project Window or just press Ctrl+2 as shown in figure

FILE TAB

Now there you will see a build.xml which can be double click to edit it’s source. Now here we can combine our jar files

into one jar via XML . Now copy and paste the following text to the end, just before the final line, which is the closing tag</project>:

[sourcecode=’html’]









[/sourcecode]

Ok i’ll explain in brief:

On the above code there you will find the line like this:
[sourcecode=’xml’] [/sourcecode]
Here you can edit the code according to your requirements

<property name="store.jar.name" value="MarsRoverViewer"/>
  • value=”MarsRoverViewer” defines the filename of the jar which is the combination of all jars.
  • property name=”stor.jar.name” define the property ‘s name which is stored in a directory /store and the with name of MarsRoverViewer which is defined in attribute value .

After all you have finished your coding phase.

Now, When you’re ready to package all of your classes and libraries into a single JAR file, switch back to the Files view in the upper left, then right-click the build.xml file. Then choose Run Target>Other Targets>package-for-store. Now the compiler will start to combine your class files and other libraries to a single JAR file named MarsRoverViewer.

Executing this Ant target will create a directory called store inside your project directory. NetBeans and Ant will then copy all of the classes and libraries into a temporary JAR file and strip out any unwanted files, placing the final result under the JAR name that you specified earlier. NetBeans will then delete the temporary file. The results are shown in Figure