0

I am having a multimodule maven project: Having three modules jar, war and ejb

I need to add ejb dependency in my war to access ejb bean so i created one ear and added them in it but still war cant find the ejb bean classes.here is the pom file of ear.Can anybody help me in this.And plz tell me can i add my ejb dependency directly in war or in parent pom coz i have read somewhere that its bad practice to add ejb dependencies directly.

http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 ecommunicate.trutheq.ussdproject pom.parent 1.0 Ussd.Project.EAR ear

<dependencies>
    <dependency>
        <groupId>ecommunicate.trutheq.ussdproject</groupId>
        <artifactId>Ussd.Project.Login</artifactId>
        <version>1.0</version>
        <type>war</type>
    </dependency>
    <dependency>
        <groupId>ecommunicate.trutheq.ussdproject</groupId>
        <artifactId>Ussd.Project.Ejb</artifactId>
        <version>1.0</version>
        <type>ejb</type>
    </dependency>
    <dependency>
        <groupId>ecommunicate.trutheq.ussdproject</groupId>
        <artifactId>Common.Utilities</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>

<build>
    <plugins>

        <plugin>

            <artifactId>maven-ear-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <earSourceDirectory>EarContent</earSourceDirectory>
                <version>6</version>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <modules>
                    <webModule>
                        <groupId>ecommunicate.trutheq.ussdproject</groupId>
                        <artifactId>Ussd.Project.Login</artifactId>
                    </webModule>

                    <ejbModule>
                        <groupId>ecommunicate.trutheq.ussdproject</groupId>
                        <artifactId>Ussd.Project.Ejb</artifactId>
                        <bundleFileName>Ussd.Project.Ejb-1.0-jar-with-dependencies.jar</bundleFileName>

                    </ejbModule>

                </modules>

            </configuration>
        </plugin>
    </plugins>
</build>

kirti
  • 4,499
  • 4
  • 31
  • 60

2 Answers2

1

The dependency in your .war module may look like the following. I am not sure why it could be considered as a bad practice and I can not think of the other way to make your ejb module accessible in your war module. Probably the author's idea was about adding ejb .jar in war's lib folder directly instead of keeping it in the .ear's lib folder. The link to the resource where you read it could help to clarify the idea

    <dependency>
        <groupId>ecommunicate.trutheq.ussdproject</groupId>
        <artifactId>Ussd.Project.Ejb</artifactId>
        <version>1.0</version>
        <type>ejb-client</type>
        <scope>provided</scope>
    </dependency>
jjd
  • 2,158
  • 2
  • 18
  • 31
  • i did add ejb dependency in war.. now its accesible but when i deploy ear my servlet is not found which is in war and there is no error still it shows 404 resource not found.can you help in this – kirti Aug 09 '14 at 04:21
  • It is a different and unrelated question. Post a new question, provide config files and the servlet code than mention me in the comment so I see your question – jjd Aug 09 '14 at 07:41
0

You can have any number of ejb jar dependencies in war module and its not a bad practice for sure.

But you should mark that dependency as "provided" in scope part in pom.xml, since its already available at the top level of that EAR.

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

Here, my-web.war can dependent on EJB.jar (with provided scope).

Sri
  • 4,613
  • 2
  • 39
  • 42