0

考虑这个结构:

/project
   /module-1
      /src/test/resources/META-INF/persistence.xml
   /module-2

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

<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 中的依赖项:

<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 以编程方式创建:

EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory(persistenceUnit);
EntityManager entityManager = entityManagerFactory.createEntityManager();

我怎样才能让它工作?谢谢。

4

1 回答 1

1

您声明的依赖项不是针对您创建的 test-jar。你应该这样声明:

<dependency>
    <groupId>com.domain.test</groupId>
    <artifactId>test-shared</artifactId>
    <type>test-jar</type>
    <scope>test</scope>
</dependency>
于 2013-03-26T15:16:05.337 回答