11

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
  • 1,041
  • 3
  • 12
  • 16

3 Answers3

22

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>
martin clayton
  • 72,583
  • 29
  • 209
  • 194
ChssPly76
  • 94,877
  • 24
  • 194
  • 191
  • 1
    Worked great! I was having a bit of difficulty understanding the documentation. – user149100 Aug 12 '09 at 17:00
  • 3
    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)" – stian Jun 30 '11 at 13:53
  • 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" – amitsalyan Jun 18 '14 at 17:33
  • @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? – ziMtyth May 16 '18 at 10:17
9

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>
sasah
  • 174
  • 1
  • 3
  • 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. – Rakesh N Apr 21 '14 at 12:46
6

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>
emarshah
  • 318
  • 2
  • 12
SmartCoder
  • 61
  • 1
  • 2