How do I create an EAR file with an ant build including certain files?

85,211

Solution 1

Ant EAR task

Everything that should go into META-INF folder should be specified via nested <metainf> fileset:

<ear destfile="${dist.dir}/${ant.project.name}.ear" 
  appxml="${conf.dir}/application.xml">
  <metainf dir="${build.dir/META-INF}"/>
  <fileset dir="${dist.dir}" includes="*.jar,*.war"/>
</ear>

Solution 2

Try this code:

    <ear destfile="deploy/iapp.ear"
         appxml="workspace/appEAR/EarContent/META-INF/application.xml">
        <fileset file="workspace/appEJB/appEJB.jar" />
        <fileset file="workspace/appWAR/appWAR.war" />
        <zipfileset file="workspace/appLIB/appLIB.jar"
                    prefix="APP-INF/lib" />
        <zipfileset dir="lib/fop" includes="*.jar" prefix="APP-INF/lib" />
        <zipfileset dir="lib/poi" includes="*.jar" prefix="APP-INF/lib" />
        <zipfileset dir="lib/gxt" includes="*.jar" prefix="APP-INF/lib" />          
        <metainf dir="workspace/appEAR/EarContent/META-INF">
            <exclude name="**/application.xml" />
            <exclude name="**/MANIFEST.MF" />
        </metainf>
        <manifest>
            <attribute name="Weblogic-Application-Version"
                       value="${deploy.revision}" />
        </manifest>
    </ear>

Solution 3

First, build a war using this;

http://ant.apache.org/manual/Tasks/war.html

than an EAR in the same Ant task.

http://ant.apache.org/manual/Tasks/ear.html

Put this in your java project directory structure:

<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." default="test_ear" name="myProject">
    <property name="build.dir" value="WebContent"/>
<target name="test_ear">
    <war destfile="C:/projects/test1.war" needxmlfile='false'>
      <fileset dir="${build.dir}" excludes="*build*.xml"/>
    </war>
    <ear destfile="C:/projects/test1EAR.ear" appxml="WebContent/META-INF/application.xml">
      <fileset dir="C:/projects/" includes="*.jar,*.war"/>
    </ear>
</target>
</project>
Share:
85,211
user149100
Author by

user149100

Updated on July 09, 2022

Comments

  • user149100
    user149100 almost 2 years

    I'm using eclipse to build an ear file using ant. I'm using oc4j, and I want to make sure that orion-application.xml is included in the build. What I'm currently using but does not work is:

       <target name="ear" depends="">
            <echo>Building the ear file</echo>
            <copy todir="${build.dir}/META-INF">
                <fileset dir="${conf.dir}" includes="orion-application.xml"/>
            </copy>
            <ear destfile="${dist.dir}/${ant.project.name}.ear" 
                    appxml="${conf.dir}/application.xml">
                <fileset dir="${dist.dir}" includes="*.jar,*.war"/>
            </ear>
        </target>

    What is the right way to add this to the ear?

  • user149100
    user149100 over 14 years
    Worked great! I was having a bit of difficulty understanding the documentation.
  • stian
    stian almost 13 years
    Works well, though I get an annoying warning: "selected ear files include a META-INF/application.xml which will be ignored (please use appxml attribute to ear task)"
  • Rakesh N
    Rakesh N about 10 years
    While this does not have enough upvotes, I think this is more comprehensive than the 'accepted' answer since it covers all variants - war, jar, appxml, manifest, app-inf/lib and meta-inf.
  • amitsalyan
    amitsalyan almost 10 years
    The annoying warning is possibly beacouse you have application.xml in your META-INF folder as well and the ANT task tries to insert the application.xml by the appxml="blah blah"
  • ziMtyth
    ziMtyth almost 6 years
    @ChssPly76 Hi, I am able to generate the ear but it comes empty! knowing that I am generating the ear from the result of the build (the folder build) but what is happening is the ear is generated before the build is done! So when executing the build again i get my ear as desired (because the build has already been done in the 1st time). Ho can I configure build.xml so that it executes the generation of the ear after the build is done?