Alex Rivera | Logout

How can I build an EAR file from a Dynamic Web Project in Eclipse?

Asked 2011-06-07T15:55:53.240
17

I'm looking at deploying a web service which I've written in Eclipse to an EAR file. I'm able to export it as a WAR and deploy it on Tomcat all fine and dandy, but the final product won't be on Tomcat, and won't be a WAR file. I'll need to use Websphere as a server, which I have access to and can deploy valid EAR files... if I had an EAR file to deploy.

So long story short, how do I export an EAR file from a Dynamic Web Project in Eclipse?

Edit
Report

1 Answer

0

for this I use an Ant build script, (you can create a new Ant file in Eclipse, store it in your dynamic web project root and then right click > run on it when you want to run it from eclipse. Something like below. Basically copy your war to a directory, ${earDir} in the script below, and build that to an EAR (an EAR is just a type of JAR) :

    <target name="buildEar" depends="init">
    <copy tofile="${earDir}/" file="yourWarFile"/>
    <copy tofile="${earDir}/META-INF/application.xml" file="localDirectory/application.xml"/>
    <copy todir="${earDir}/META-INF">
        <fileset dir="localDirectory" includes="was.policy" />
    </copy>
    <jar jarfile="localDir/something.ear" basedir="${earDir}">
        <!-- Define the properties for the Manifest file. -->
        <manifest>
            <attribute name="Implementation-Vendor"  value="Company name"/>
            <attribute name="Implementation-Title"   value="Application Title"/>
            <attribute name="Implementation-Version" value="version and build number"/>
        </manifest>     
    </jar>
</target>

Your was.policy file will be something like this (not good to give all permissions but you can change it later once you have it up and running):

    //
// Template policy file for enterprise application.
// Extra permissions can be added if required by the enterprise application.
//
// NOTE: Syntax errors in the policy files will cause the enterprise application FAIL to start.
//       Extreme care should be taken when editing these policy files. It is advised to use
//       the policytool provided by the JDK for editing the policy files
//       (WAS_HOME/java/jre/bin/policytool). 
//

grant codeBase "file:${jars}" {
};

grant codeBase "file:${connectorComponent}" {
};

grant codeBase "file:${webComponent}" {
};

grant codeBase "file:${ejbComponent}" {
}
answered 2011-06-24T14:22:07.447

Your Answer