There are several approaches to building a jar that contains jars. They typically involve using ant to bundle the files into the jar and a special class loader. Writing the build.xml file and the class loader can be tedious. Fortunately, the Fat Jar eclipse plugin simplifies the process and includes the One-JAR class loader.
Installing the plugin can be done using Software Updates:
Click on Add Site
Enter the web site URLSelect the Fat Jar plugin and click on Install
Click Finish
Restart eclipse to finish the installation.
To build your project with external jars included, click on Export
Click on Other and select the Fat Jar Exporter
Select the project
Enter the name of the output jar, select the main class, and check off the One-JAR option to use the One-JAR class loader.
Clicking on next opens a dialog to select the jars to include, the default selects all external jars. Unlike a typical executable jar, all the imported classes are not included so take the default and click on finish. The Fat Jar plugin will build the jar with the external jars included, note that the final jar can become quite large.
No comments:
Post a Comment