0

この構造を考えてみましょう。

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

モジュール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で定義されているpersitenceunits(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 に答える