根据生产或测试环境,在Eclipse中使用不同的JPA.persistence.xml [英] Use different JPA.persistence.xml in Eclipse depending on production or test environment

查看:80
本文介绍了根据生产或测试环境,在Eclipse中使用不同的JPA.persistence.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在与gradle合作,并拥有默认的项目结构:

We are working with gradle and have the default project structure:

/src
   /main
     /java
     /resources
       /META-INF
         persistence.xml
   /test
     /java
     /resources
       /META-INF
         persistence.xml

虽然我们用gradle运行我们的junit测试,一切都很好没有关于源路径等的特殊的gradle配置):使用'test'的persistence.xml。

While we run our junit tests with gradle, all is fine (we do not have any special gradle configuration concerning source paths or the like): the persistence.xml from 'test' is used.

但是,如果我们尝试运行我们的junit测试使用eclipse,始终使用'main'的peristence.xml。

But if we try to run our junit tests with eclipse, always the peristence.xml from 'main' is used.

我们如何配置eclipse以使用main的persistence.xml作为一个启动配置,但是对于所有junit测试,test的persistence.xml是

How can we configure eclipse to use the persistence.xml from 'main' for one launch configuration, but the persistence.xml from 'test' for all junit tests?

推荐答案

关于从类路径加载的资源:

Another thing to try, if this is a general problem about resources loaded from your classpath:

在Ec中lipse的项目属性Java Build Path-> Order and Export将您的测试文件夹放在src文件夹的上方。

In Eclipse's project properties, Java Build Path->Order and Export, put your test folder above your src folder.

然后在部署程序集下排除您的测试文件夹

Then under Deployment Assembly, exclude your test folder

这将确保在Eclipse中直接启动测试时,您将首先搜索测试文件夹的classpath资源。但是当您作为webapp启动时,测试文件夹将从 WEB-INF / classes 中排除。

That will ensure that when you launch tests directly from within Eclipse, you will search the test folder first for classpath resources. But when you launch as a webapp instead, the test folders would be excluded from WEB-INF/classes.

这篇关于根据生产或测试环境,在Eclipse中使用不同的JPA.persistence.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆