In this tutorial you will see how to create EAR (Enterprise Archive) Maven project in eclipse. EAR is a Java EE standard format use to package one or more module into a single module so that we can deploy many module as single archive module on application server.
EAR file contains main XML files called deployment descriptors which says how many module package together and deploy on the application server. EAR file is generally a standard zip file (JAR File) with .ear extension. One or more entries inside deployment descriptor which represent module of the application puts inside meta data directory called META-INF.
We will use Eclipse Kepler to create EAR project. Here we will create two module JAR and WAR and include inside EAR module and all module will be created inside parent module. Please follow steps below:
- Final project structure:
- Create parent module: JavaHonkParent
- Click File –> New –> Other –> Maven –> Maven Project then click Next
- On next window choose as given below then click next:
- Fill out input field as given below then click finish. This will create parent project name: JavaHonkParent:
- Now add new JAR module to parent : JavaHonkJARModule. Right click JavaHonkParent –> New –> Other –> Maven Module –> Next
- Give module name as below then click next:
- Choose archetype quick start then click next:
- Fill out field as below then click finish. This will create new JAR module name: JavaHonkJARModule:
- Now create WAR module. To create right click parent module JavaHonkParent –> New –> Other –> Maven –> Maven module –> Next
- Fill out fields as below:
- Next choose archetype webapp then click next:
- Please enter information as below then click finish. This will create WAR module name: JavaHonkWARModule
- Finally now let’s create EAR module. Right click parent module JavaHonkParent –> New –> Other –> Maven –> Maven Module –> Next
- Enter name and choose create a simple project check box as below then click next:
- Type packaging type ear then click finish as below:
- Now we have to add both JAR and WAR dependencies to EAR module. To add dependencies open pom.xml from EAR module and add dependencies as below:
- As you see we have added JAR and WAR dependencies in EAR module. Don’t forget to save pom.xml file:
- To print sample message on web page please open index.jsp from WAR module and include below:
- Next start build process for all modules. As you have seen all our module EAR, WAR and JAR are added inside parent module so if we run mvn install from parent then this will create JAR, WAR and include inside EAR file. To build right click JavaHonkParent –> Run As –> Maven Install
- Once you see build successful message on console then refresh and check all individual module. You will see JAR, WAR and EAR got created as below:
- Maven install also create application.xml files please double click to open and see module and context URL. Finally we are ready to deploy this EAR on JBoss server.
- Now to deploy ear on JBoss server please copy ear file to JBoss (jboss-6.1.0.Finalserverdefaultdeploy) folder and start the server and check in log file or console if ear deployed or not. Search below context if you see means it deployed successfully:
- Enter below URL in browser you will see below:
- That’s it. We have created maven EAR project and deployed successfully on JBoss server.
- For more information about EAR project please visit this link
Reference : javahonk