开发者

Embedded GlassFish container for unit testing session beans in NetBeans pointing to wrong domain

开发者 https://www.devze.com 2023-03-20 10:17 出处:网络
I have written unit tests for several session 开发者_开发百科beans I have created. When I try to run them, however, NetBeans gives me the following error:

I have written unit tests for several session 开发者_开发百科beans I have created. When I try to run them, however, NetBeans gives me the following error:

No EJBContainer provider available. The following providers: org.glassfish.ejb.embedded.EJBContainerProviderImpl returned null from createEJBContainer call.

I highly suspect that this is the root cause of the issue:

SEVERE: EJB6004:Specified application server installation location [C:\Development\GlassFish\3.1\glassfish\domains\domain1] does not exist.

It's right. Domain1 does not exist. I created a "development" domain myself and deleted domain1 but it seems there is a lingering reference of which I have no clue where to modify it. The non-embedded container the embedded container is referring to is registered in NetBeans as well and correctly hooked up to the development domain. There are no problems with regular deployments of the project.

Any help very much appreciated!


I believe ScatteredWar is outdated. After a bunch of searching I found the incredibly helpful post Quick introduction to Embeddability of GlassFish Open Source Edition 3.1, which gives this snippet:

If your archive is not pre-built, instead it's components are scattered in multiple directories, then you may be interested in using the scattered archive APIs:

import org.glassfish.embeddable.; import org.glassfish.embeddable.archive.;

Deployer deployer = glassfish.getDeployer();
// Create a scattered web application.
ScatteredArchive archive = new ScatteredArchive("testapp", ScatteredArchive.Type.WAR);
// target/classes directory contains my complied servlets
archive.addClassPath(new File("target", "classes"));
// resources/sun-web.xml is my WEB-INF/sun-web.xml
archive.addMetadata(new File("resources", "sun-web.xml"));
// resources/MyLogFactory is my META-INF/services/org.apache.commons.logging.LogFactory
archive.addMetadata(new File("resources", "MyLogFactory"), "META-INF/services/org.apache.commons.logging.LogFactory");
deployer.deploy(archive.toURI())

Other docs: Oracle GlassFish Server 3.1 Embedded Server Guide and The updated API.


Adam Bien and Arun Gupta speak about ways to embed GlassFish for unit testing.

The main piece is this:

        GlassFish glassfish = new GlassFish(port);
        ScatteredWar war = new ScatteredWar(NAME,
            new File("src/main/resources"),
            new File("src/main/resources/WEB-INF/web.xml"),
            Collections.singleton(new File("build/classes").toURI().toURL()));
        glassfish.deploy(war);

An alternative approach would be to use OpenEJB to do your unit testing, as this will ensure that you're sticking to standards. Adam as has has an entry on setting that up.

0

精彩评论

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