开发者

How can I exclude one persistence.xml from the test classpath in Eclipse without using Maven/Ant?

While running JUnit integration tests inside Eclipse, I have two persistence.xml files on the classpath - one containing the configuration for the test cases and another one for production. I need to find a way to exclude the persistence.xml for production from the test classpath.

Constraints: I am not allowed to use Maven or Ant, just Eclipse Helios SR1 (with JUnit). The JPA 2 persistence provider is EclipseLink 2.2.0. As I have to use ClearCase 7.0 as VCS, no linked resources are possible, as described here, for example.

Here is the rough project structure:

project-datamodel (containing the Entity beans)
\- src/resources/META-INF/persistence.xml (for production; want to exclude it)
\- test/resources/META-INF/persistence.xml (for test)

project-service (containing the Session beans)
开发者_开发知识库\- ejbModule

project-service-it (containing the JUnit integration tests for the Session beans)
\- test


I had this problem because my two persistence.xml files (production and test) used the same <persistence-unit> name. As mentioned above, the classpath order does not matter as EclipseLink apparently finds all persistence.xml files before deciding which to use. I solved it by renaming the test PU in both the xml file and the call from my unit test:

@BeforeClass
public static void setup() {
    em = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME).createEntityManager();
}


You can edit the classpath when you create a run configuration for your unit tests (Eclipse will create one automatically if you pick "Run As -> Junit Test" from the context menu.

When editing that new run configuration you can add custom folders on the "Classpath" tab and move them up in front of the default classpath. I have not tried it, but that should do it, because in the test it would find the test persistence.xml first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜