【发布时间】:2016-10-14 14:39:48
【问题描述】:
更新 问题似乎与 Ubuntu 操作系统是虚拟化的事实有关,即我使用 Vmware Workstation 创建了主机操作系统 (Windows) 和来宾操作系统 (Ubuntu)。
当我将 EJB 部署到主机 (Windows) 上的 Glassfish 时;我可以在主机 (Windows) 或来宾 (Ubuntu) 上使用 servlet 客户端查找 EJB。我还可以为主机或来宾指定设置以查找 EJB。我相信这就是问题所在,即无论servlet中是否提供了主机设置或来宾设置,查找总是在主机上完成。有没有人有类似的经历,你是怎么解决的。
原始问题
请看下面的代码:
Properties props = new Properties();
props = new Properties();
props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
props.setProperty("org.omg.CORBA.ORBInitialHost", "192.168.163.128");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
try
{
InitialContext ctx = new InitialContext(props);
RemoteInterfaceRemote r = (RemoteInterfaceRemote) ctx.lookup("java:global/Course/RemoteInterface!com.w0051977.dao.RemoteInterfaceRemote");//!com.w0051977.dao.RemoteInterfaceRemote
String greeting = r.Greeting("Ian");
System.out.println("got here");
} catch (NamingException n)
{
System.out.println(n.toString());
}
代码位于 Servlet 中,并按预期工作,例如问候变量包含:“下午好伊恩”。 Servlet 在 Windows PC 上运行并连接到托管企业 bean 的 Windows 服务器。
但是,当我将 bean 移动到 Linux (Ubuntu) PC 时,我遇到了问题。上面的代码将在 Linux PC 上的 Servlet 中运行(在这种情况下,客户端和服务器在同一台 PC 上)。但是,我无法让上面的代码在 Windows PC 上的 servlet 中工作。
当 Windows 客户端 (servlet) 连接到 Linux (Ubuntu) 服务器时,您有什么特别需要做的吗?我显然在移动服务器时更改了上面代码中的 IP 地址。例外是:
Lookup failed for 'java:global/Course/RemoteInterface' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=ubuntu, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming
Glassfish 控制台(在 Ubuntu 上)的输出是:
[2016-10-14T08:57:16.824-0700] [glassfish 4.1] [INFO] [] [javax.enterprise.system.tools.deployment.common] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460636824] [levelValue: 800] [[
visiting unvisited references]]
[2016-10-14T08:57:16.890-0700] [glassfish 4.1] [INFO] [] [javax.enterprise.system.tools.deployment.common] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460636890] [levelValue: 800] [[
visiting unvisited references]]
[2016-10-14T08:57:17.238-0700] [glassfish 4.1] [INFO] [AS-EJB-00054] [javax.enterprise.ejb.container] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637238] [levelValue: 800] [[
Portable JNDI names for EJB RemoteInterface: [java:global/Course/RemoteInterface, java:global/Course/RemoteInterface!com.w0051977.dao.RemoteInterfaceRemote]]]
[2016-10-14T08:57:17.248-0700] [glassfish 4.1] [INFO] [AS-EJB-00055] [javax.enterprise.ejb.container] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637248] [levelValue: 800] [[
Glassfish-specific (Non-portable) JNDI names for EJB RemoteInterface: [com.w0051977.dao.RemoteInterfaceRemote#com.w0051977.dao.RemoteInterfaceRemote, com.w0051977.dao.RemoteInterfaceRemote]]]
[2016-10-14T08:57:17.432-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637432] [levelValue: 900] [[
WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]]
[2016-10-14T08:57:17.472-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637472] [levelValue: 900] [[
WELD-000411: Observer method [BackedAnnotatedMethod] public org.glassfish.jms.injection.JMSCDIExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]]
[2016-10-14T08:57:17.482-0700] [glassfish 4.1] [WARN] [] [org.jboss.weld.Event] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460637482] [levelValue: 900] [[
WELD-000411: Observer method [BackedAnnotatedMethod] org.glassfish.sse.impl.ServerSentEventCdiExtension.processAnnotatedType(@Observes ProcessAnnotatedType<Object>, BeanManager) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.]]
[2016-10-14T08:57:18.078-0700] [glassfish 4.1] [INFO] [] [javax.enterprise.system.core] [tid: _ThreadID=96 _ThreadName=admin-listener(7)] [timeMillis: 1476460638078] [levelValue: 800] [[
Course was successfully deployed in 1,282 milliseconds.]]
我花了几天时间研究这个。请帮忙。
sudo lsof -i:3700 的输出是(请注意,我没有根据@RCs 评论将 IP 版本更改为 4:
从 Windows PC ping Ubuntu PC 时有回复。
这是 Linux 服务器上的 JNDI 树:
远程服务器上的 JNDI 查找名称应该是什么?我需要在本地 Glassfish PC(Windows PC)上进行任何配置吗?
【问题讨论】:
-
我可以提供更多信息来鼓励回复吗?我花了几天时间谷歌搜索并尝试了许多不同的东西。
-
你能把
sudo lsof -i:3700的输出(从ubuntu盒子里运行)和ping ubuntu从Windows盒子里运行的输出贴出来吗? -
@RC,我已将输出发布到原始帖子。谢谢。
-
Ubuntu PC 是虚拟化 (VMWARE) PC。虚拟化 PC 的主机是 Windows PC。
-
好的,根据 lsof 输出,java 正在侦听 IPV6 而不是 IPV4 并且您在客户端使用 ipv4,那就是可能是这里的问题
标签: java ubuntu jakarta-ee glassfish-4