The Java Warehouse is the repository for Java and JavaFX applications submitted by developers for distribution through the Java Store to hundreds of millions of desktops worldwide. The Java Warehouse Developer Center Release Notes make clear that there is currently no way to upload applications composed of several Java Archive (JAR) files into the Java Warehouse. However, there is a workaround: Just concatenate each of the user and library classes into a single JAR file. This is very easy to do for both Java and JavaFX projects using NetBeans IDE 6.7.1. To demonstrate how to do this, let's use one of the sample Java projects that is included in the NetBeans IDE 6.7.1 distribution: the Mars Rover Viewer. Open the NetBeans IDE, select File > New Project, then scroll down to the ![]() Figure 1 - Creating the Mars Rover Viewer Sample Project in NetBeans.
We've chosen this project because it makes use of a popular compile-time library that is not included with the standard Java Development Kit (JDK): the Swing Application Framework. To verify that this library is being used, right-click on the project in the upper left pane and choose Properties. From there, select Libraries on the left pane to verify that the Swing Application Framework is indeed listed, as shown in Figure 2. Then click OK to close the Project Properties dialog box. ![]() Figure 2 - The Mars Rover Viewer Application Uses the Swing Application Framework Library.
In order to bundle all of the libraries into a single JAR file, you will need to edit the project's Ant file, which is called
<target name="package-for-store" depends="jar">
<!-- Change the value of this property to be the name of your JAR,
minus the .jar extension. It should not have spaces.
<property name="store.jar.name" value="MyJarName"/>
-->
<property name="store.jar.name" value="MarsRoverViewer"/>
<!-- don't edit below this line -->
<property name="store.dir" value="store"/>
<property name="store.jar" value="${store.dir}/${store.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${store.jar}"/>
<delete dir="${store.dir}"/>
<mkdir dir="${store.dir}"/>
<jar destfile="${store.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
</manifest>
</jar>
<zip destfile="${store.jar}">
<zipfileset src="${store.dir}/temp_final.jar"
excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${store.dir}/temp_final.jar"/>
</target>
Note that you must change the following line in the Ant code above to match your particular project. <property name="store.jar.name" value="MarsRoverViewer"/> The property ![]() Figure 3 - Additions to the Project's
build.xml File Relative to the Closing Tag.From here, you can continue normal development, editing Java source files and compiling and running as necessary. Figure 4 shows the Mars Rover Viewer application fully built and running within the NetBeans IDE. ![]() Figure 4 - Running the Mars Rover Viewer Within the NetBeans IDE.
When you're ready to package all of the classes and libraries into a single JAR file, switch back to the Files view in the upper left, then right-click the ![]() Figure 5 - Executing the
package-for-store Ant Target From the Files Tab Inside the NetBeans IDE.Executing this Ant target will create a directory called ![]() Figure 6 - The Final JAR File, Ready to Upload to the Java Warehouse.
That's all there is to it — you can use this JAR file to upload to the Java Warehouse. Note that if you get an error stating that the If you'd like to verify that the JAR file contains the appropriate libraries, you can use one of three methods:
For More Information
Rate This ArticleDiscussionWe welcome your participation in our community. Please keep your comments civil and on point. You can optionally provide your email address to be notified of repliesyour information is not used for any other purpose. By submitting a comment, you agree to these Terms of Use. |
Robert Eckstein has worked with Java technology since its first release. Formerly a programmer and editor for O'Reilly Media, Inc., and a programmer for Motorola's cellular technology division, he is now a senior staff writer on java.sun.com.
| |||||||
|
| ||||||||||||