16

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?

ZKSteffel
  • 1,115
  • 5
  • 13
  • 22

2 Answers2

16

You need to create an Enterprise Application Project (basically, an EAR) in Eclipse, add the Dynamic Web Project to the EAR project, and then export the whole thing.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
  • @Matt-For some reason after I do this, websphere gives me an error: `The EAR file could be corrupt and/or incomplete. Make sure that the application is at a compatible Java 2 Platform, Enterprise Edition (J2EE) Level for WebSphere Application Server.` Is there a configuration setting I'm missing, perhaps? – ZKSteffel Jun 07 '11 at 16:12
  • I was missing a lot of configuration settings, as shown by some of my other postings. So once I got my language versions correct, I was able to create the EAP with a dependency on my project and ensure application.xml was included, then export this as an EAR file. – ZKSteffel Jun 10 '11 at 17:50
  • Sorry I wasn't more useful in resolving the error, but I'm glad you got it working. – Matt Ball Jun 10 '11 at 18:11
  • 2
    How do you "add the Dynamic Web Project to the EAR project"? – Wes Oct 02 '14 at 18:35
  • in order to add the DW project to the EAR, do i need to place it on EarContent folder? – luis alberto juarez Oct 27 '20 at 03:14
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}" {
};

grant codeBase "file:${application}" {
  permission java.security.AllPermission;
};

Your application.xml file will be something like this:

<?xml version="1.0" encoding="UTF-8"?>
<application id="Application_ID" version="1.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
    <display-name>yourAppName</display-name>
    <module id="WebModule_1240219352859">
        <web>
            <web-uri>yourWarFile.war</web-uri>
            <context-root>urlToApplication</context-root>
        </web>
    </module>
</application>

The ids there should be ok they need to be unique per EAR I believe (or is it server cant remember).

I hope this helps.

Gurnard
  • 1,773
  • 22
  • 43
  • hey @gurnard, I have a similar problem, except I need to deploy my `.ear` on `weblogic`. I am facing some issues while accessing the project after installing it on the oracle administrator console. I cant seem to figure out how to access the index.jsp page that my project has. Any idea on what maybe going wrong? – TheLuminor Dec 04 '15 at 12:28
  • here is the question that I have posted as well, please do take a look, it would help you know where exactly im getting stuck. @gurnard http://stackoverflow.com/questions/34086464/how-to-correctly-deploy-a-ear-file-on-oracle-weblogic-administrator-console – TheLuminor Dec 04 '15 at 12:29