首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >maven测试中的persistence.xml依赖

maven测试中的persistence.xml依赖
EN

Stack Overflow用户
提问于 2013-03-26 22:44:24
回答 1查看 1K关注 0票数 0

考虑一下这个结构:

代码语言:javascript
复制
/project
   /module-1
      /src/test/resources/META-INF/persistence.xml
   /module-2

在module-1中创建测试jar。module-1/pom.xml:

代码语言:javascript
复制
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
    <execution>
        <goals>
            <goal>test-jar</goal>
        </goals>
    </execution>
</executions>
</plugin>

此测试jar是module-2/pom.xml中的依赖项:

代码语言:javascript
复制
<dependency>
<groupId>com.domain.test</groupId>
<artifactId>module-1</artifactId>
<scope>test</scope>
<type>jar</type>
</dependency>

问题是,在模块2的测试中,找不到/src/test/resources/META-INF/persistence.xml中定义的固定单元(PU)。PU是通过编程创建的:

代码语言:javascript
复制
EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(persistenceUnit);
EntityManager entityManager = entityManagerFactory.createEntityManager();

我怎么才能让它工作呢?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-26 23:16:05

您声明的依赖项没有指向您创建的test-jar。你应该这样声明它:

代码语言:javascript
复制
<dependency>
    <groupId>com.domain.test</groupId>
    <artifactId>test-shared</artifactId>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15639953

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档