【发布时间】: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