You probably put your persistence.xml in the wrong place in your archive. Try printing the archive contents.
@RunWith(Arquillian.class)
public class SomeTest {
@Deployment
public static WebArchive createDeployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class)
.addAsResource(new File("src/main/resources/META-INF/persistence.xml"), "META-INF/persistence.xml")
.addAsWebInfResource(new File("src/main/webapp/WEB-INF/beans.xml"), "beans.xml");
war.writeTo(System.err, org.jboss.shrinkwrap.api.formatter.Formatters.VERBOSE);
System.err.println();
return war;
}
@Test
public void blah() {
// ...
}
}
Note in the above that I've used
addAsResource(..., "META-INF/persistence.xml"). In a web archive, addAsManifestResource(..., "persistence.xml") won't work as it'll place it in /META-INF/persistence.xml and the correct (albeit very very strange) location is /WEB-INF/classes/META-INF/persistence.xmlIt's a stupid mistake, but when you can't directly see the archive structure it's not always immediately obvious. JBoss's error message doesn't help - "persistence unit named null" ?.
Hopefully a future ShrinkWrap release will add an archive-format-aware API for placing persistence.xml in its wacky location.
All the below are wrong:
- addAsWebInfResource(..., "persistence.xml") -> /WEB-INF/persistence.xml
- addAsWebInfResource(..., "META-INF/persistence.xml") -> /WEB-INF/META-INF/persistence.xml
- addAsManifestResource(..., "persistence.xml") -> /META-INF/persistence.xml
- addAsResource(..., "persistence.xml") -> /WEB-INF/classes/persistence.xml
/WEB-INF/classes/META-INF/persistence.xml
Thanks a lot for your valuable help
ReplyDelete