【问题标题】:how to import java files from ejb module in web app?如何从 web 应用程序中的 ejb 模块导入 java 文件?
【发布时间】:2016-07-02 05:08:09
【问题描述】:

我创建了 ear 项目,我有 2 个名为: mavenproject4-web mavevnproject4-ejb

我尝试从 web 模块中的 ejb 模块导入一些接口和实体。但我不能。 我尝试通过 pom.xml 将 ejb 模块作为依赖项添加到 web 模块中。然后我的问题解决了。是正确的方式吗?

添加依赖项后,我尝试运行项目,但出现此异常:

严重:准备应用程序时出现异常:无法解析与名为 [mavenproject4-ear#mavenproject4-ejb- 的模块范围内的 persistence-context-ref-name [mysessionbeans.StudentDAOImpl/entityManager] 对应的持久性单元1.0.jar]。请验证您的申请。

我的持久化 xml 在 ejb 模块的“src/main/resources”中。图像中有关项目结构的详细信息:

我的网络应用 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>

谢谢

【问题讨论】:

  • mavenproject4-ear 依赖不应该是ejb jar吗?
  • 我相信你的 POM 文件中有一个错字:你应该有 mavenproject4-ejb 而不是将 mavenproject4-ear 作为依赖项。

标签: maven jpa jakarta-ee ejb ear


【解决方案1】:

ejb jar 文件需要在 ear 文件中。但我也认为persistence.xml 文件需要在EJB jar 文件的META-INF 文件夹中。我怀疑你在那里的方式,它在根文件夹中。尝试将其移动到 src/main/resources/META-INF/persistence.xml

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

【讨论】:

  • OP persistence.xml 在 src/main/resources/META-INF* 文件夹中。
  • 是的,我看图片的距离不够近...我专注于不太清晰的文字。然后我想知道依赖部分是否不正确(引用的是EAR而不是JAR)
猜你喜欢
  • 2019-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-15
  • 2012-08-23
  • 2014-10-14
相关资源
最近更新 更多