考虑这个结构:
/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();
我怎样才能让它工作?谢谢。