0
votes

I have a EAR maven based project that its structure is like below :

------ root
  |
  |--- EAR
        |
        |---- EJB (JAR)
        |
        |---- WEB (WAR)

I want to make a goal for it that first clean all three EAR , EJB , WEB ,module then first install EJB after that install WEB and at the end install EAR because of their dependencies

how I have to do it in just one command line in maven?

here is my pom.xml for root

   <url>http://jboss.org/jbossas</url>
<licenses>
    <license>
        <name>Apache License, Version 2.0</name>
        <distribution>repo</distribution>
        <url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
    </license>
</licenses>
<modules>
    <module>ejb</module>
    <module>web</module>
    <module>ear</module>
</modules>

<properties>
<dependencyManagement>
    <dependencies>

        <!-- Define the version of the EJB jar so that we don't need 
            to repeat ourselves in every module -->
        <dependency>
            <groupId>RHAMavenBased</groupId>
            <artifactId>RHAMavenBased-ejb</artifactId>
            <version>${project.version}</version>
            <type>ejb</type>
        </dependency>

        <!-- Define the version of the WAR so that we don't need to repeat 
            ourselves in every module -->
        <dependency>
            <groupId>RHAMavenBased</groupId>
            <artifactId>RHAMavenBased-web</artifactId>
            <version>${project.version}</version>
            <type>war</type>
            <scope>compile</scope>
        </dependency>
1

1 Answers

1
votes

You need the maven multi module project setup. Take a look into this tutorial here. Everything you need is configurable with this

Edit

There is an entry in your parent pom as

    <dependency>
        <groupId>RHAMavenBased</groupId>
        <artifactId>RHAMavenBased-ejb</artifactId>
        <version>${project.version}</version>
        <type>ejb</type>
    </dependency>

I am not mistaken , here ${project.version} is the version of the parent pom that you are building and since it is specified in the parent pom, this dependency trickles down to all sub-modules which is not a good idea in your case, since the EJB project will have dependency on itself ( this is bad design ). Ideally a module should never be dependant on itself. So our first issue is redundant dependency in the modules. Secondly since this is defined in the parent pom and the ${project.version} is being read from the parent pom, we may have version mismatches here or even un-synchronized jars in m2, target and on the build path.