NetBeans 7.0、JUnit 和 Glassfish Embedded 3.1:不起作用
我正在尝试在 Win7Professional 机器中使用 NB 7.0、JUnit 和嵌入式 Glassfish 服务器进行 JUnit 测试 J2EE Web 应用程序。
我将其分解为使用单个会话 Bean 来测试一个简单的 Hello-World Web 应用程序。
我的类路径中有 glasfish-embedded-static-shell.jar,并且还尝试使用 glassfish-embedded-all-3.1,但它也不起作用。
现在这是我用来测试 bean 的代码:
import javax.ejb.embeddable.EJBContainer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
public class SimpleBeanTest {
private static EJBContainer container;
public SimpleBeanTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
container = javax.ejb.embeddable.EJBContainer.createEJBContainer();
}
@AfterClass
public static void tearDownClass() throws Exception {
container.close();
}
@Test
public void testCountToThree() throws Exception {
System.out.println("countToThree");
SimpleBean instance = (SimpleBean) container.getContext().lookup("java:global/classes/SimpleBean");
int expResult = 0;
int result = instance.countToThree();
assertEquals(expResult, result);
}
}
这是它的结果:
19.06.2011 09:31:56 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient
INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.
19.06.2011 09:31:56 org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SCHWERWIEGEND: MNTG0301:Cannot process XML ProbeProvider, xml = META-INF/gfprobe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:javamail:smtp-transport
(StackTrace here)
19.06.2011 09:31:57 org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SCHWERWIEGEND: MNTG0301:Cannot process XML ProbeProvider, xml = META-INF/mojarra-jsf-api-probe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:jsf:faces-servlet
(StackTrace here)
19.06.2011 09:31:57 org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SCHWERWIEGEND: MNTG0301:Cannot process XML ProbeProvider, xml = jersey-gf-server-probe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:jersey:server-hidden
(StackTrace here)
19.06.2011 09:31:57 org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SCHWERWIEGEND: MNTG0301:Cannot process XML ProbeProvider, xml = jersey-gf-statsprovider-probe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:jersey:server
(StackTrace here)
19.06.2011 09:31:57 org.glassfish.ha.store.spi.BackingStoreFactoryRegistry register
INFO: Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
19.06.2011 09:31:57 org.glassfish.ha.store.spi.BackingStoreFactoryRegistry register
INFO: Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
19.06.2011 09:31:57 com.sun.enterprise.v3.server.AppServerStartup run
SCHWERWIEGEND: Startdienst konnte nicht gestartet werden: com.sun.enterprise.naming.GlassFishNamingBuilder
19.06.2011 09:31:57 com.sun.enterprise.v3.server.AppServerStartup run
INFO: GlassFish Server Open Source Edition 3.1 (43) Startzeit: Embedded (597ms), Startdienste(929ms), gesamt(1.526ms)
19.06.2011 09:31:57 org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run
INFO: JMXStartupService: JMXConnector system is disabled, skipping.
更新: 这是任何测试都会抛出的异常:
No EJBContainer provider available
Provider named org.glassfish.ejb.embedded.EJBContainerProviderImpl threw unexpected exception at create EJBContainer:
java.lang.RuntimeException
java.lang.RuntimeException: java.lang.IllegalStateException: AMX Booter MBean is already registered: amx-support:type=boot-amx
at org.glassfish.internal.embedded.Server.<init>(Server.java:290)
at org.glassfish.internal.embedded.Server.<init>(Server.java:66)
at org.glassfish.internal.embedded.Server$Builder.build(Server.java:176)
(Stack Trace here)
Caused by: java.lang.IllegalStateException: AMX Booter MBean is already registered: amx-support:type=boot-amx
我已经重新安装了 NetBeans 两次,但它也不起作用。
I am trying to JUnit Test a J2EE Web Application with NB 7.0, JUnit and the embedded Glassfish Server in a Win7Professional machine.
I broke it down to just test a plain simple Hello-World Web App with a single Session Bean.
I have the glasfish-embedded-static-shell.jar in my classpath, and also tried to use the glassfish-embedded-all-3.1 but it also didn't work.
Now here's the code I use to test the bean:
import javax.ejb.embeddable.EJBContainer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;
public class SimpleBeanTest {
private static EJBContainer container;
public SimpleBeanTest() {
}
@BeforeClass
public static void setUpClass() throws Exception {
container = javax.ejb.embeddable.EJBContainer.createEJBContainer();
}
@AfterClass
public static void tearDownClass() throws Exception {
container.close();
}
@Test
public void testCountToThree() throws Exception {
System.out.println("countToThree");
SimpleBean instance = (SimpleBean) container.getContext().lookup("java:global/classes/SimpleBean");
int expResult = 0;
int result = instance.countToThree();
assertEquals(expResult, result);
}
}
And here's what comes out of it:
19.06.2011 09:31:56 com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient
INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default.
19.06.2011 09:31:56 org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SCHWERWIEGEND: MNTG0301:Cannot process XML ProbeProvider, xml = META-INF/gfprobe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:javamail:smtp-transport
(StackTrace here)
19.06.2011 09:31:57 org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SCHWERWIEGEND: MNTG0301:Cannot process XML ProbeProvider, xml = META-INF/mojarra-jsf-api-probe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:jsf:faces-servlet
(StackTrace here)
19.06.2011 09:31:57 org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SCHWERWIEGEND: MNTG0301:Cannot process XML ProbeProvider, xml = jersey-gf-server-probe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:jersey:server-hidden
(StackTrace here)
19.06.2011 09:31:57 org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SCHWERWIEGEND: MNTG0301:Cannot process XML ProbeProvider, xml = jersey-gf-statsprovider-probe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:jersey:server
(StackTrace here)
19.06.2011 09:31:57 org.glassfish.ha.store.spi.BackingStoreFactoryRegistry register
INFO: Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
19.06.2011 09:31:57 org.glassfish.ha.store.spi.BackingStoreFactoryRegistry register
INFO: Registered org.glassfish.ha.store.adapter.cache.ShoalBackingStoreProxy for persistence-type = replicated in BackingStoreFactoryRegistry
19.06.2011 09:31:57 com.sun.enterprise.v3.server.AppServerStartup run
SCHWERWIEGEND: Startdienst konnte nicht gestartet werden: com.sun.enterprise.naming.GlassFishNamingBuilder
19.06.2011 09:31:57 com.sun.enterprise.v3.server.AppServerStartup run
INFO: GlassFish Server Open Source Edition 3.1 (43) Startzeit: Embedded (597ms), Startdienste(929ms), gesamt(1.526ms)
19.06.2011 09:31:57 org.glassfish.admin.mbeanserver.JMXStartupService$JMXConnectorsStarterThread run
INFO: JMXStartupService: JMXConnector system is disabled, skipping.
UPDATE:
And this is the exception which would be thrown by any test:
No EJBContainer provider available
Provider named org.glassfish.ejb.embedded.EJBContainerProviderImpl threw unexpected exception at create EJBContainer:
java.lang.RuntimeException
java.lang.RuntimeException: java.lang.IllegalStateException: AMX Booter MBean is already registered: amx-support:type=boot-amx
at org.glassfish.internal.embedded.Server.<init>(Server.java:290)
at org.glassfish.internal.embedded.Server.<init>(Server.java:66)
at org.glassfish.internal.embedded.Server$Builder.build(Server.java:176)
(Stack Trace here)
Caused by: java.lang.IllegalStateException: AMX Booter MBean is already registered: amx-support:type=boot-amx
I have reinstalled NetBeans twice and it doesn't works either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,我执行了以下操作:
1) 我安装了 Glassfish 3.1.1 并将其链接到我的项目。首先,我使用“工具”-“服务器”-“添加服务器”添加服务器...然后右键单击我的 EJB 项目并选择“属性”-“运行”-“Glassfish 3.1.1”
2) 在我的 EJB pom.xml 中,我使用此依赖项(确保 systemPath 变量指向正确的文件):
3) 在我的 EJB pom.xml 中,我删除其他人说我必须的依赖项如果我收到错误“提供商已映射...”,请添加
它!现在,我使用 JPA 2 进行的 EJB JUnit 测试工作得非常顺利!希望这有帮助!
I had the same issue and I did the following:
1) I installed Glassfish 3.1.1 and linked it to my project. First I added the server with Tools - Servers - Add Server... Then I right-clicked my EJB project and selected Properties - Run - Glassfish 3.1.1
2) In my EJB pom.xml I use this dependency (make sure the systemPath variable points to the correct file):
3) In my EJB pom.xml I removed the dependency other people said I have to add it if I get the errors "Provider already mapped..."
That's it! Now my EJB JUnit tests with JPA 2 work like a charm! Hope this helps!
似乎服务器启动正常(其中一些例外是预期的,但我无法确认是否全部例外)。
尝试按照以下步骤操作: http://javadude.wordpress.com/2010/02/22/tutorial-most-simple-test-application-for-embedded-glassfish-netbeans-hudson/(忘记哈德逊部分)。 IDE 应该负责为您添加依赖项。
哦,另一件事,由于您使用的是 Windows,因此尝试以管理员身份运行 Netbeans(右键单击选项)并看看会发生什么情况不会有什么坏处。
干杯,
更新
也许您遇到了这个错误:
看看是否像这样启动容器对您有用:
Seems like the server is starting ok (some of those exceptions are expected, but I can't confirm if all of them are).
Try to follow those steps: http://javadude.wordpress.com/2010/02/22/tutorial-most-simple-test-application-for-embedded-glassfish-netbeans-hudson/ (forget about the Hudson part). The IDE should take care of including the dependencies for you.
Oh, another thing, since you are using Windows, it won't hurt to try to run Netbeans as Admin (right click option) and see what happens.
Cheers,
Update
Maybe you are hitting this bug:
See if starting the container like this works for you: