I have a JEE / Maven project with a number of entity classes and session beans.
It builds and I can use the EJB module from several web modules with JSF and so on. The module uses the data connection defined in the Payara server. Now i want to build some Junit test scripts to automatically test my session beans using Maven and Payara embedded. >From other articles I concluded that I can have this structure: /src /main /java /resources /META-INF persistence.xml /test /java /resources /META-INF persistence.xml which will make it possible for me to use two different persistence.xml files. One problem I have now is that payara server requires the JNDI name of the data source like this: jdbc//myDatasource while payara embedded requires the format: java:app/jdbc/myDataSource So it gives me problems when I run the test and when I want to deploy. But I can't get netBeans / Maven / Payara embedded to use the persistence.xml file located under test. It consistently use the one located in main. Which means that my JUint test will not run since they can't find the correct datasource. My persistence.xml in main: ...<persistence-unit name="dk.myDS" transaction-type="JTA"> <jta-data-source>jdbc/druid</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> ... my persistence.xml in test ....<persistence-unit name="dk.myDS" transaction-type="JTA"> <jta-data-source>java:app/jdbc/druid</jta-data-source><exclude-unlisted-classes>false</exclude-unlisted-classes> .... How do I force netBeans / maven to use the correct persistence.xml? Is there another solution to this problem? I refuse to believe that I'm the only one having this problem. But I have not seen any solution to this case. If I delete my persistence.xml under main my test runs as expected. When i copy persistence.xml back into main i get the following error: Caused by: com.sun.appserv.connectors.internal.api.ConnectorRuntimeException: Invalid resource : jdbc/druid__pm at org.glassfish.jdbcruntime.service.JdbcDataSource.validateResource(JdbcDataSource.java:82) at org.glassfish.jdbcruntime.service.JdbcDataSource.setResourceInfo(JdbcDataSource.java:63) If I don't have persistence.xml in main I can't deploy my app since i don't have the mapping between persistenceContext and jdbc connection. Catch 22. Thanks in advance