Thursday, 11 June 2009

Creating Jars in Eclipse

Frequently we may wish to build an open-source Java library and export it as a JAR. Asssuming we have created a new workspace in Eclipse, e.g. Apache Commons, composed of multiple projects e.g. Lang (which we have imported into Package Explorer using "Create Java Project from Existing Ant Build File") we can create a JAR for the Lang project as follows:

1. Right click on Project in Package Explorer
2. Select Export..
3. Select Java/JAR file
4. Enter a name for the file e.g. project name and version number, like commons-lang-2.4.jar

Once the JAR is built (by default it will be in the directory for the current workspace), you can inspect the file as follows:

jar -tvf commons-lang-2.4.jar | grep class | wc -l

will return a count of 127 class files.

No comments: