I have EJB TimeServiceEJB with remote interfce TimeService. In Deploy descriptor of my EJB module there is:
<ejb-name>TimeServiceEJB</ejb-name>
...
<env-entry>
<description>... </description>
<env-entry-name>variable</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>10</env-entry-value>
</env-entry>
I need to get this variable from client application and be able to edit it. I trying to do it this way:
Properties p = new Properties();
p.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
p.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
p.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
p.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
p.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext iniCtx = new InitialContext(p);
Integer variable = (Integer) iniCtx.lookup("java:comp/ejb/TimeServiceEJB/variable");
But i got nothing. Tried to lookup in different ways (“java:global/ejb/TimeServiceEJB/variable”, “java:comp/env/TimeServiceEJB/variable”, “java:global/ear-name/module-name/TimeServiceEJB/) – always had “javax.naming.NameNotFoundException: No object bound for …”
Tried to set mappingName of this variable by annotaion @Resource(name=”variable”, mappedName=”env/variable”), and lookup by “env/variable”, but got NameNotFoundException.
Is there any ideas, how to get this variable? And the second question is: can i edit its value?
Environment entries are only visible in the application component’s naming context (i.e.
java:comp/envfrom theInitialContextwithin the EJB or web module where it is declared). (Exception: Java EE 6 provides ways to declare and access module, application, and global-scoped environment entries, but those require specific environment entry prefixes. See EE.5.2.2 from the Java EE 6 specification for more information.)Environment entry values cannot be modified in JNDI at runtime. I’d suggest exposing a separate method on your EJB that gets and sets this value locally.