用于在 NetBeans 中对指向错误域的会话 bean 进行单元测试的嵌入式 GlassFish 容器

发布于 2024-11-19 16:44:41 字数 503 浏览 1 评论 0原文

我已经为我创建的几个会话 bean 编写了单元测试。然而,当我尝试运行它们时,NetBeans 给出以下错误:

没有可用的 EJBContainer 提供程序。以下提供程序:org.glassfish.ejb.embedded.EJBContainerProviderImpl 从 createEJBContainer 调用返回 null。

我高度怀疑这是问题的根本原因:

严重:EJB6004:指定的应用程序服务器安装位置 [C:\Development\GlassFish\3.1\glassfish\domains\domain1] 不存在。

是的。域 1 不存在。我自己创建了一个“开发”域并删除了domain1,但似乎有一个挥之不去的参考,我不知道在哪里修改它。嵌入式容器所引用的非嵌入式容器也在 NetBeans 中注册,并正确连接到开发域。项目正常部署没有问题。

非常感谢任何帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无边思念无边月 2024-11-26 16:44:41

我相信分散战争已经过时了。经过大量搜索后,我发现了这篇非常有用的帖子 GlassFish 开源版本 3.1 的嵌入性快速介绍,其中提供了以下代码片段:

如果您的存档不是预先构建的,而是其组件分散在多个目录中,那么您可能有兴趣使用分散的存档 API:

import org.glassfish.embeddable.;
导入 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())

其他文档:Oracle GlassFish Server 3.1 嵌入式服务器指南 和更新后的 API

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.

谁的新欢旧爱 2024-11-26 16:44:41

Adam BienArun Gupta 谈论嵌入方法用于单元测试的 GlassFish。

主要部分是这样的:

        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);

另一种方法是使用 OpenEJB 进行单元测试,如下所示这将确保您遵守标准。 Adam 有一个关于设置的条目

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文