0
votes

i create ear project and i have 2 module named: mavenproject4-web mavevnproject4-ejb

i try to import some interface and entity from ejb module in web module.But i can't. i tried to add ejb module as dependency into web module by pom.xml.Then my problem fixed.Is it right way?

after adding dependency i tried to run project and i got this exception:

Severe: Exception while preparing the app : Could not resolve a persistence unit corresponding to the persistence-context-ref-name [mysessionbeans.StudentDAOImpl/entityManager] in the scope of the module called [mavenproject4-ear#mavenproject4-ejb-1.0.jar]. Please verify your application.

my persistence xml is in "src/main/resources" in ejb module.Detail information about project structure in image: enter image description here

My web app pom.xml

<?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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>mavenproject4</artifactId>
        <groupId>az.lsim</groupId>
        <version>1.0</version>
    </parent>

    <groupId>az.lsim</groupId>
    <artifactId>mavenproject4-web</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

<name>mavenproject4-web</name>

<properties>
    <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>az.lsim</groupId>
        <artifactId>mavenproject4-ear</artifactId>
        <version>1.0</version>
        <type>jar</type>
    </dependency>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <compilerArguments>
                    <endorseddirs>${endorsed.dir}</endorseddirs>
                </compilerArguments>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.6</version>
            <executions>
                <execution>
                    <phase>validate</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${endorsed.dir}</outputDirectory>
                        <silent>true</silent>
                        <artifactItems>
                            <artifactItem>
                                <groupId>javax</groupId>
                                <artifactId>javaee-endorsed-api</artifactId>
                                <version>7.0</version>
                                <type>jar</type>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Thanks

1
Shouldn't the mavenproject4-ear dependency be the ejb jar instead? - EdH
I believe you have a typo in your POM file: instead of having mavenproject4-ear as a dependency, you should have mavenproject4-ejb. - António Ribeiro

1 Answers

0
votes

The ejb jar file will need to be in the ear file. But I also think that the persistence.xml file needs to be in META-INF folder in the EJB jar file. I suspect that the way you have it there, it's in the root folder. Try moving it to src/main/resources/META-INF/persistence.xml

See http://docs.oracle.com/cd/E14101_01/doc.1013/e13981/pkgapp001.htm