Problem: Our EJBs and WARs (in an EAR) have references to an URL. I want to deploy this URL in JNDI one time and resolve all references by linking on the deployed URL. This is the same concept as websphere default URL provider, but how do I do that in jboss? Which mbean can I use? Do I have to define a special service? Right now, I resolved the link using the jboss.xml file and it works. But I do not want to repeat this in each EJB.
My code uses a URL like this: ... public static final String AUDITLOG_PATH = "java:comp/env/AuditLogPath"; ... Object rep = new InitialContext().lookup(InternalJNDIRefererences.AUDITLOG_PATH);
In ejb-jar.xml: ... <resource-ref> <description></description> <res-ref-name>AuditLogPath</res-ref-name> <res-type>java.net.URL</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref>
After looking around, I found that I can do this: Add the following to conf/jboss-service.xml: ... <mbean code="org.jboss.naming.JNDIBindingServiceMgr" name="pm-urls:service=JNDIBindingServiceMgr"> <attribute name="BindingsConfig" serialDataType="jbxb"> <jndi:bindings xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" xmlns:jndi="urn:jboss:jndi-binding-service:1.0" xs:schemaLocation="urn:jboss:jndi-binding-service:1.0 resource:jndi-binding-service_1_0.xsd" >
Then I see it in the global JNDI tree: ... +- urls (class: org.jnp.interfaces.NamingContext) | +- jboss-home (class: java.net.URL)
Which is fine.
As is, this is a working solution.
The only improvement I would like to see is: How can I define the same behavior outside of the jboss-service.xml file? The reason I'm asking is because I don't like the idea of adding to an existing configuration file. When we install a new jboss from the distribution, I like to be able to unzip the whole package and then, only add the config file required. If I keep the urls in the jboss-service.xml file, I cannot do this: I must open (manually or programmatically) the jboss-service.xml file and add the mbean section at the end. I would prefer to simply copy a standalone file to do the same. Any suggestion?