Prev | Next

TOC | Index

J2EETM Developer's Guide
Running the J2EE Tools


The packager tool is a command-line script allows you to package J2EE components. This tool is for advanced users who do not want to use the Application Deployment Tool to package J2EE components. With the packager, you can create the following component packages:

EJB .jar File

The syntax for packaging an EJB .jar file follows:

packager <root-directory> package/Class1.class:package/
Class2.class:pics/me.gif ejb-jar.xml ejb.jar


The following command packages the EJB classes and the ejb-jar.xml deployment descriptor into the myEjbJar.jar file:

packager -ejbJar /home/duke/classes/ 
HelloHome.classHelloEJB.class:HelloRemote.class:Util.class test/ejb-
jar.xml myEjbJar.jar 

Web Component .war File

The syntax for packaging a web component .war file follows:

packager -webArchive[-classpath servletorjspbean/classes [ -
classFiles package/MyClass1.class: package/MyClass2.class ] ] 
<content-root> [-contentFiles login.jsp:index.html:images/me.gif] 
web.xml myWebApp.war

Simple Example:

The following command packages the myWebPage.xml deployment descriptor and the page in WebPageDir/Hello.html into the myWebPage.war file:

packager -webArchive myWebPageDir myWebPage.xml myWebPage.war 

Specifying Individual Content Files:

Suppose that you add a Hello.jsp file to the directory myWebPageDir, don't want the Hello.html file any more, and modify your .xml file accordingly. You can individually specify the content files to add using the -contentFiles flag:

packager -webArchive myWebPageDir -contentFiles Hello.jsp 
myWebPage.xml myWebPage.war
Without the -contentFiles option, the following command will produce the same .war file because it includes everything under the directory myWebPageDir:

packager -webArchive myWebPageDir -contentFiles Hello.jsp:Hello.html 
myWebPage.xml myWebPage.war 

Specifying Servlets and JSP Files:

Suppose that you write a servlet and compile it into your classes directory, modifying the .xml file for its deployment attributes. Its class file is classes/package/Servlet1.class. The following command includes the servlet class file because it is under the classes directory:

packager -webArchive -classpath classes myWebPageDir -contentFiles 
Hello.jsp myWebPage.xml myWebPage.war. 
The following command specifies that only the package/Servlet1.class and packageB/Servlet.class files are to be included:

packager -webArchive -classpath classes -classFiles package/
Servlet1.class:packageB/Servlet.class myWebPageDir -contentFiles 
Hello.jsp myWebPage.xml myWebPage.war 
The next command adds the Hello.html file back into the .war file:

packager -webArchive -classpath classes -classFiles package/
Servlet1.class:packageB/Servlet.class myWebPageDir -contentFiles 
Hello.jsp:Hello.html myWebPage.xml myWebPage.war 

Application Client .jar File

The syntax for packaging an application client .jar file follows:

packager -applicationClient    <root-directory> package/
Class1.class:package/Main.class:pics/me.gif package.Main client.xml 


The following command creates the appClient.jar file:

packager  classes hello/HelloClient.class:hello/HelloUtil.class 
package.Main client.xml appClient.jar

J2EE Application .ear File

The syntax for packaging a J2EE application .ear file follows:

packager -enterpriseArchive    myWeb.war:myEJB.jar:myOtherApp.ear [-
alternativeDescriptorEntries myWeb/web.xml:myEjb/myEjb.xml: ][-
libraryJars ejblib.jar:ejblib1.jar] myAppName myApp.ear


In the following command, the optional -alternativeDescriptorEntries flag allows you to specify the external descriptor entry name of each component as you wish it to appear in the .ear file:

packager -enterpriseArchive    myWeb.war:myEJB.jar:appClient.ear -
alternativeDescriptorEntries myWeb/web.xml:myEjb/myEjb.xml:client/
client.xml myAppName myApp.ear 
After packaging, any manipulation of the deployment information will not be written back into the component files inside the .ear file, but to the entry names in the .ear file that you specified.

Specifying the Runtime Deployment Descriptor

The preceding example specified the -enterpriseArchive flag to create a portable J2EE application .ear file. This file is portable because you can import it into any J2EE environment that conforms to the J2EE Specification. Although you can import the file into the Application Deployment Tool, you cannot deploy it on the J2EE server until it contains a runtime deployment descriptor. This deployment descriptor is an XML file that contains information such as the JNDI names of the application's enterprise beans.

In the following command, the -setRuntime flag instructs the packager to insert the runtime deployment descriptor (sun-j2ee-ri.xml) into the myApp.ear file:

packager -setRuntime MyApp.ear sun-j2ee-ri.xml
To obtain an example of the runtime deployment descriptor, extract it from a .ear file that you've already deployed:

jar -xvf SomeApp.ear
The DTD of the runtime deployment descriptor is in the lib/dtds/sun-j2ee-ri-dtd file of your J2EE SDK installation.

Note: The runtime deployment descriptor (sun-j2ee-ri.xml) is not required by the J2EE Specification. This descriptor is unique to the J2EE SDK and may change in future releases.

Prev | Next

TOC | Index

Copyright © 2000 Sun Microsystems, Inc. All rights reserved.