Skip to main content

GlassFish Migration: WebLogic's Split Directory to Ear

Posted by sekhar on September 29, 2008 at 9:42 AM PDT

GlassFish Migration: WebLogic's Split Directory To Ear

As I wrote in the blog on href="http://weblogs.java.net/blog/sekhar/archive/2008/09/_when_migrating_1.html">Verification Tools for Migration to GlassFish, GlassFish
verifier tool is handy for verifiying the Java EE compliance
of an application. Verifier is run as follows

                verifier --portablity archive

at seems simple enough to run, but it does require an
archive (ear/war/jar/rar). The source application server
(e.g. WebLogic ) from which the application is being migrated
to GlassFish will usually provide a mechnism to generate an
archive file. Here, I will examine the generation of an ear
file on WebLogic 9.2 when split directory development is being
used. A lot of the samples in WebLogic 9.2 distribution use
the split directory development model. And I ran into a problem
while trying to generate an archive file for the
JSP Simple Tag sample
that I had migrated earlier. I will describe both the problem
and the workaround.

Background on Split Directory Development

The split directory development model is targeted towards
iterative development. The essence of this type of development
is that there are two directories:

  • src directory : This directory contains sources,
    including deployment descriptors.

  • build directory : This directory contains
    compiled classes.

WebLogic provides an Ant task - wlpackage - to package the src
and build directory contents into a single EAR file or an
archive directory in an exploded format. For e.g.

       
        <!-- package to an ear file -->
        <wlpackage srcdir="${src.dir}" destdir="${dest.dir}
                   toFile="${ear.file}" />

        <!-- package to an exploded directory -->
        <wlpackage srcdir="${src.dir}" destdir="${dest.dir}
                   toDir="${ear.exploded.dir}" />

Every WebLogic 9.2 server sample's build.xml contained an Ant target
"package.exploded.ear" that packaged the src and build directory
into an ear in exploded format. But there was no ant target
for packaging into a J2EE ear. Note: The WebLogic 9.2
BuildXMLGen facility does generate a build.xml with an Ant
target for building both ear file as well as a standard J2EE
expoloded directory. I am not sure why the build.xml files in
the samples do not have such a target.

So I thought I would use wlpackage to package an ear file. The
problem I ran into is that the ear file generated was not Java
EE compliant. The files for the web module were packaged in an
exploded format rather than being packaged into a war file
first, and then packaging the war file into the ear
file. Thus, the web-uri XML element in the application.xml
points to an exploded directory rather than a war file,
causing the verifier to fail with an exception.

        <!-- Archive contents produced by wlpackage -->
        <!-- Note: jspSimpleTagWar is a directory not a war file -->
             META-INF/
             META-INF/MANIFEST.MF
             META-INF/application.xml
             jspSimpleTagWar/
             jspSimpleTagWar/ExamplesFooter.jsp
             ...

        <!-- META-INF/application.xml -->
        <?xml version="1.0" encoding="UTF-8"?>
        <application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
          <description>JSP 1.2 Simple Tag API Example</description>
          <display-name>JSP 1.2 Simple Tag API Example</display-name>
            <module>
              <web>
                <web-uri>jspSimpleTagWar</web-uri>
                <context-root>jsp_simpleTag</context-root>
              </web>
            </module>
        </application>

I worked around the above problem as described below.

  • Build the ear in exploded format on WebLogic 9.2. Every
    server sample in WebLogic 9.2 distribution has a
    build.xml file an ant target "package.exploded.ear",
    which will build package the contents of src and build
    directory into an EAR file in exploded directory format.
          <target name="package.exploded.ear">
              <wlpackage srcdir="${dist}" destdir="${examples.build.dir}/${bean.ear}"
                         toDir="${dist}" />
          </target>
  • Make a copy of application.xml to gf-application.xml and
    change from directory to a jar file
    name. This will replace the application.xml.
            <!-- META-INF/application.xml -->
            <?xml version="1.0" encoding="UTF-8"?>
            <application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
              <description>JSP 1.2 Simple Tag API Example</description>
              <display-name>JSP 1.2 Simple Tag API Example</display-name>
                <module>
                  <web>
                    <web-uri>jspSimpleTag.war</web-uri>
                    <context-root>jsp_simpleTag</context-root>
                  </web>
                </module>
            </application>
  • Run the WebLogic supplied ant target to create an
    ear in exploded directory format. In the JSP Simple Tag
    example, you can do this by:
               cd <weblogic92>/samples/server/examples/src/examples/webapp/jsp/tags/simple/
               ant package.exploded.ear

    This creates /samples/server/examples/src/examples/webapp/jsp/tags/simple/jspSimpleTagEar exploded directory

  • Run the following target with will take the exploded
    directory and package the ear file correctly. (For
    simplicity, I hardcoded values for directories).
          <target name="all">
             <!-- package the J2EE exploded ear into an archive -->
            <mkdir dir="archivedir"/>
            <jar destfile="archivedir/jspSimpleTag.war" basedir="jspSimpleTagEar/jspSimpleTagWar"/>
            <copy todir="archivedir/META-INF">
                <fileset dir="jspSimpleTagEar/META-INF"
                         excludes="**/application.xml"/>
            </copy>
            <copy file="gf-application.xml" tofile="archivedir/META-INF/application.xml"/>
            <jar destfile="jspSimpleTag.ear" basedir="archivedir"/>
            </target>

The generated ear will look like this.

        Ear file format
        META-INF/
        META-INF/MANIFEST.MF
        META-INF/application.xml
        META-INF/weblogic-application.xml
        jspSimpleTag.war

Summary

WebLogic supports a split directory development. WebLogic
provides ant task for packaging an ear file. But
the ear generated cannot be processed by the ear file. I have
showed one way to get around this problem using an ant script
that packages the contents of an exploded archive directory
into an ear file for consumption by verifier.

It would be useful if the verifier tool itself could be used on
an exploded directory. But that is another topic for another
day.

Related Topics >>

Comments

I have a one .war component and one META-INF folder, this folder contains the application.xml, weblogic-application.xml, MANIFEST.MF with this i have created one .ear file. While i am deploying this .ear file in weblogic 9.2 console, i am getting the following error. Unable to access the selected application. Exception in AppMerge flows' progression and in server logs i can see the following message, " element does not contain a for "controllerClass". Page Flow actions in this module may not be handled correctly.> " Can any one of you please help me to resolve this problem. Thanks in advance.