考虑一下这个结构:
/project
/module-1
/src/test/resources/META-INF/persistence.xml
/module-2在module-1中创建测试jar。module-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();我怎么才能让它工作呢?谢谢。
发布于 2013-03-26 23:16:05
您声明的依赖项没有指向您创建的test-jar。你应该这样声明它:
<dependency>
<groupId>com.domain.test</groupId>
<artifactId>test-shared</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>https://stackoverflow.com/questions/15639953
复制相似问题