2

I have developed a web application that up till now I was testing locally using Tomcat as the server.

I now wish to move to Oracle WebLogic Server 11gR1 (10.3.5) for further use. I looked up and found out that there are .ear files such as .war file that are supported. Since I am using Eclipse, I have downloaded and installed the Weblogic Plugin in it and successfully added the server too.

However, if I wish to deploy a .ear file on WebLogic what are the steps that I need to follow? Is there a specific file structure that my existing Maven Project needs to have?

I am not successfully able to export the .ear file from eclipse. I understand that once the .ear file is ready, I can move the same to my WebLogic C:\*BaseDirectry*\*BaseName*\applications folders and run it from there.

But how do I successfully create a .ear file of my existing maven project?

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
TheLuminor
  • 1,411
  • 3
  • 19
  • 34

1 Answers1

1

The structure I would suggest in these cases is to have a maven multimodule project providing your application module (jar packaging), a war module (war packaging) and an ear module (ear packaging) in order to have a clear separation of concerns and have maven build a single artifact per module.

If your project is currently a classic maven project, you can create an aggregator module project (pom packaging) as following:

    <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>your.group.id</groupId>
    <artifactId>your.artifact.id-aggregator</artifactId>
    <packaging>pom</packaging>
    <version>your.version</version>

  <modules>
    <module>your.artifact.id-application</module>
    <module>your.artifact.id-war</module>
    <module>your.artifact.id-ear</module>
  </modules>
</project>

This means the aggregator project will point to maven modules existing in subfolders your.artifact.id-application, your.artifact.id-war and your.artifact.id-ear. The application module is a simple Maven project providing your application logic and building a jar file out of it. It is not mandatory, but it can also point as a parent to the aggregator project (aggregation and inheritance are two different things in Maven, which can be mixed together or used differently). You can declare the parent project in modules as following:

<parent>
    <groupId>your.group.id</groupId>
    <artifactId>your.artifact.id-aggregator</artifactId>
    <version>your.version</version>
</parent>

In the application module, you don't need to specify packaging, since by default it will jar, while in the ear and war module, packaging will be respectively ear and war.

The war module will need to have the application module as its dependency. The WAR module is also a good location to place integration tests. You could also configure here a jetty maven plugin start/stop as part of pre/post-integration-test phase. The war module will also provide the required src\main\webapp\WEB-INF structure

The ear module will need to have the war module as its dependency and it is important to specify its type, war, as following:

<dependencies>
    <dependency>
        <groupId>your.group.id</groupId>
        <artifactId>your.application.id-war</artifactId>
        <version>your.version</version>
        <type>war</type>
    </dependency>
</dependencies>

Note the war. The ear module will also provide the required src\main\application\META-INF structure. The ear module can configure the maven-ear-plugin simply as following:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <configuration>
                <modules>
                    <webModule>
                        <groupId>your.group.id</groupId>
                        <artifactId>your.artifact.id-war</artifactId>
                        <bundleFileName>your.artifact.id.war</bundleFileName>
                        <contextRoot>/your.artifact.id</contextRoot>
                    </webModule>
                </modules>
            </configuration>
        </plugin>
    </plugins>
</build>

its application.xml file (under src\main\application\META-INF) can simply look like below:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application PUBLIC "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" "http://java.sun.com/dtd/application_1_3.dtd">
<application>
  <display-name>your.group.id.your.artifact.id_ear</display-name>
  <module>
    <web>
      <web-uri>your.artifact.id.war</web-uri>
      <context-root>/your.artifact.id</context-root>
    </web>
  </module>
</application>

It might look over-complicated as a structure, but it gives you control over modules and artefacts, meets maven best practices and improves your focus (i.e. application code only on the application module, integration tests only on the war module).

A_Di-Matteo
  • 26,902
  • 7
  • 94
  • 128
  • Sounds viable. Though is there no way that I can simply create a `.ear` by? I do see an option to import a `.ear` project in `eclipse` however, It is beyond my understanding as to why that isn't working. – TheLuminor Dec 01 '15 at 08:39
  • 1
    I actually found two related answers which provide nearly the same approach: http://stackoverflow.com/questions/1134894/maven2-best-practice-for-enterprise-project-ear-file and http://stackoverflow.com/questions/6829961/create-complete-ear-project-with-maven-and-eclipse-helios, while here http://javahonk.com/create-maven-ear-project-eclipse/ there is a step-by-step example, I didn't go through the whole article but, again, he provides guide on implementing the same approach. – A_Di-Matteo Dec 01 '15 at 08:44
  • The link - http://javahonk.com/create-maven-ear-project-eclipse/ tha tyou posted, is what I am able to make sense of. So, right at the start where he says - `Create parent module: JavaHonkParent Click File –> New –> Other –> Maven –> Maven Project then click Next` - The very first step, he is creating an empty `maven` project and building a `.war` file and a `.jar` file and further adding them to the parent `.ear` file - All sounds and seems good. Makes complete sense. However, he created an empty project and possibly then worked on it later. I already have a project. What do I do about that? – TheLuminor Dec 01 '15 at 09:33
  • He actually described the approach I explained in my answer. The empty project (packaging pom) is the parent/aggregator project. In this project you need to declare modules=other maven projects (one for the war, one for the ear, one for your implementation=jar). You can create another maven project as a subfolder of the parent project and link it as a module. In eclipse, you can create new Maven Module (and not Project) which will be automatically linked to the parent if your right click was done on the parent folder (link = declare it as a module in the parent POM). – A_Di-Matteo Dec 01 '15 at 11:24
  • Thanks for the reply! Yes, I did figure that out and started to do the same with my project. I've been getting an `error` in the process that I asked as a new question. here is the link http://stackoverflow.com/questions/34019243/eclipse-not-being-able-to-find-pom-xml-location please take a look and let me know what you think? – TheLuminor Dec 01 '15 at 11:27
  • Okay so, I finally managed to get through with that. and got stuck at the last step - `Maven Clean Install`. When I run a clean install, I get the following error - `[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar (default-jar) on project ProjectNameJARModule: Error assembling JAR: For artifact {org.glassfish.jersey.containers:jersey-container-servlet-core:null:jar}: The version cannot be empty. -> [Help 1]` – TheLuminor Dec 01 '15 at 13:08
  • any idea why this is happening? @A Di Matteo – TheLuminor Dec 02 '15 at 10:15
  • you created this question for this issue, right? http://stackoverflow.com/questions/34021575/failed-to-execute-goal-org-apache-maven-pluginsmaven-jar-plugin2-4jar Better to continue on that thread (which I already answered actually) – A_Di-Matteo Dec 02 '15 at 11:24