The J2EETM Tutorial
Home
TOC
PREV TOC NEXT Search
Feedback

Packager

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


Note: To make them easier to read, the examples that follow contain line breaks within the commands. When typing these commands, do not include the line breaks.

EJB JAR File

Syntax

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

Example

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

packager -ejbJar /home/duke/classes/
HelloHome.class:HelloEJB.class:HelloRemote.class:Util.class
hello-jar.xml HelloEJB.jar  

Web Application WAR File

Syntax

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 

Example: Creating a Simple WAR File

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  

Example: Specifying Individual Content Files

Suppose that you add a Hello.jsp file to the directory myWebPageDir, later decide that you don't want the Hello.html file any more, and modify your .xml file accordingly. You can individually specify the content files to add by 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  

Example: 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

Syntax

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

Example

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

Syntax

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

Example: Creating an EAR File

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.

Example: 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 deploytool, 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.

Resource Adapter RAR File

Syntax

packager -connector <root-directory> file1:file2 
ra.xml myConnector.rar 

For examples, see TBD.

Home
TOC
PREV TOC NEXT Search
Feedback