I’m running Glassfish 3.1.2 embedded to unit test my application. I set up a ScatteredArchive like this:
archive.addClassPath(new File("target/classes"));
archive.addClassPath(new File("src/test/resources"));
archive.addMetadata(new File("src/main/webapp/WEB-INF/web.xml"));
In this way glassfish can find the servlets that are specified in the web.xml. Unit testing these works perfect. However, what glassfish can’t find are any web contents, like javascript, images, etc.
How do I tell a ScattedArchive where the web contents are?
You can use a different constructor for the ScatteredArchive:
which is described very briefly in the Oracle GlassFish Server 3.1.2 Embedded Server Guide for release 3.1.2. The topDir parameter is used to point to the ‘top’ of the archive, which would be the root directory of your war file. That is where your web content would usually be.