使用JNDI在不同Java程序之间共享对象

使用JNDI在不同Java程序之间共享对象,java,jakarta-ee,jndi,serializable,apache-tomee,Java,Jakarta Ee,Jndi,Serializable,Apache Tomee,我试图运行以下示例,但没有成功 目的是在不同虚拟机上运行的两个Java程序之间通过JNDI共享对象。我正在使用TomEE 1.5.1和TomEE 1.6 我正在使用的JNDI参数是: Hashtable<String, String> ctxProps = new Hashtable<String, String>(); ctxProps.put("java.naming.factory.initial","org.apache.openejb.client.Remote

我试图运行以下示例,但没有成功

目的是在不同虚拟机上运行的两个Java程序之间通过JNDI共享对象。我正在使用TomEE 1.5.1和TomEE 1.6

我正在使用的JNDI参数是:

Hashtable<String, String> ctxProps = new Hashtable<String, String>();
ctxProps.put("java.naming.factory.initial","org.apache.openejb.client.RemoteInitialContextFactory");
ctxProps.put("java.naming.provider.url", "http://myjndihost.com:8080/tomee/ejb");
ctxProps.put("java.naming.security.principal", "tomee");
ctxProps.put("java.naming.security.credentials", "tomee");
它通过javax.naming.OperationNotSupportedException执行:

Exception in thread "main" javax.naming.OperationNotSupportedException
    at org.apache.openejb.client.JNDIContext.createSubcontext(JNDIContext.java:551)
    at javax.naming.InitialContext.createSubcontext(InitialContext.java:483)
    at demo.Sharing.connect(Sharing.java:32)
    at demo.Sharing.<init>(Sharing.java:20)
    at demo.TestSet.main(TestSet.java:9)
当然,下一步将运行TestGet.java,但时间还没有到,因为 我还不能成功地运行测试集

原始示例取自此处,使用WebLogic

非常感谢。
Pablo.

OpenEJB试图告诉您“JNDI上下文对于您来说是只读的,客户端应用程序”。与其他容器(例如JBoss)不同,Tomcat的InitialContext实现是只读的。因此,如果我使用JBoss而不是OpenEJB,这个示例一定运行良好?您知道如何避免OpenEJB中的这种“只读”功能吗?谢谢你说得对,它与JBoss完美结合。非常感谢你!
public class TestSet
{
    public static void main(String[] args) throws Exception
    {
        Sharing share = new Sharing();
        share.put("fecha", new Date());
    }
}
Exception in thread "main" javax.naming.OperationNotSupportedException
    at org.apache.openejb.client.JNDIContext.createSubcontext(JNDIContext.java:551)
    at javax.naming.InitialContext.createSubcontext(InitialContext.java:483)
    at demo.Sharing.connect(Sharing.java:32)
    at demo.Sharing.<init>(Sharing.java:20)
    at demo.TestSet.main(TestSet.java:9)
Exception in thread "main" javax.naming.OperationNotSupportedException
    at org.apache.openejb.client.JNDIContext.bind(JNDIContext.java:511)
    at javax.naming.InitialContext.bind(InitialContext.java:419)
    at demo.Sharing.put(Sharing.java:39)
    at demo.TestSet.main(TestSet.java:10)