3
votes

im working on a web application with maven and Jboss 7 wich conatins 3 modules ejb ear and war so the war will have the ejb as dependancy and the ejb will be in the same time a module of the ear so when i do this i get the same ejb twice this tree

ear
...Mywar
........Myejb
...Myejb

is this structure is correct or i should change another

the pom.xml for the war :

   <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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>tn.war.ep</groupId>
  <artifactId>businessModule</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>  
     .....
     <dependency>
    <groupId>tn.linckia.epgp</groupId>
    <artifactId>ejbModule</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <type>ejb</type>
    </dependency>
  </dependencies>
</project>

the pom.xml for the ear :

  <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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>tn.war.ep</groupId>
  <artifactId>earModule</artifactId>
  <version>0.0.1</version>
  <packaging>ear</packaging>

  <build>
  <plugins>

    <plugin>
      <artifactId>maven-resources-plugin</artifactId>
      <version>2.4</version>
      <configuration>
        <encoding>UTF-8</encoding>
      </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
    </plugin>

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-ear-plugin</artifactId>
        <version>2.6</version>
        <configuration>
        <modules>
          <webModule>
            <groupId>tn.war.ep</groupId>
            <artifactId>businessModule</artifactId>
            <bundleFileName>businessModule.war</bundleFileName>
            <contextRoot>/businessModule</contextRoot>
          </webModule>
          <ejbModule>
            <groupId>tn.war.ep</groupId>
            <artifactId>ejbModule</artifactId>
           <bundleFileName>ejbModule.jar</bundleFileName>
          </ejbModule>
        </modules>
        <displayName>Security</displayName>
      </configuration>
    </plugin>
  </plugins>
  <finalName>AuthModule</finalName>
</build>
  <dependencies>
  <dependency>
    <groupId>tn.war.ep</groupId>
    <artifactId>businessModule</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <type>war</type>
  </dependency>
<dependency>
            <groupId>tn.war.ep</groupId>
            <artifactId>ejbModule</artifactId>
           <version>0.0.1-SNAPSHOT</version>
          <type>ejb</type>
          </dependency>
  </dependencies>

</project>
3

3 Answers

3
votes

Right way to configure EAR Module is to have the EJB jar dependency with "provided" scope in WAR module and having EJB jar directly under EAR like the below:

EAR
|
|-lib/someutil.jar
|-EJB.jar
|-my-web.war
|  |-WEB_INF/lib
|    |-coolutil.jar
|-EJB2.jar

But the my-web.war can dependent on the any EJB.jar, but its resolved in runtime by container. So, mark that ejb dependency as "provided" (by container) in WAR's pom.xml.

1
votes

Option : #1

Yon don't even need a ear. You can just put all your EJBs as jars inside the war. Just add the EJB projects as dependencies in your War project.

Option : #2

If you still want EAR. All EJB projects output should be jars. And web project output should be war. And at last these EJB jars and web war would be placed in one EAR. This is a old fashion way, to keep it simple you could follow the method which I explained above in Option #1.

0
votes

I had this issue and changing the ejb packaging tag from ejb to jar in the ejb modules pom.xml fixed the issue. No idea why!