JEE6 Global JNDI Name and Maven Deployment
Posted
by wobblycogs
on Stack Overflow
See other posts from Stack Overflow
or by wobblycogs
Published on 2010-05-10T16:22:23Z
Indexed on
2010/05/10
16:24 UTC
Read the original article
Hit count: 604
I'm having some problems with the global JNDI names of my EJB resources which is (or at least will) cause my JNDI look ups to fail. The project is being developed on Netbeans and is a standard Maven Web Application. When my application is deployed to GF3.0 the application name is set to something like:
com.example_myapp_war_1.0-SNAPSHOT
which is all well and good from Netbeans point of view because it ensures the name is unique but it also means all the EJBs get global names such as this:
java:global/com.example_myapp_war_1.0-SNAPSHOT/CustomerService
This, of course, is going to cause problems because every time the version changes all the global names change (I've tested this by changing the version and the names indeed changed). The name is being generated from the POM file and it's a concatenation of:
<groupId>com.example</groupId>
<artifactId>myapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
Up until now I've got away with just injecting all the resources using @EJB but now I need to access the CustomerService EJB from a JSF Converter so I'm doing a JNDI look up like this:
try {
Context ctx = new InitialContext();
CustomerService customerService = (CustomerService)ctx.lookup( "java:global/com.example_myapp_war_1.0-SNAPSHOT/CustomerService" );
return customerService.get(submittedValue);
} catch( Exception e ) {
logger.error( "Failed to convert customer.", e );
return null;
}
which will clearly break when the application is properly released and the module name changes. So, the million dollar question: how can I set the modle name in maven or how do I recover the module name so that I can programatically build the JNDI name at runtile. I've tried setting it in the web.xml file as suggested by that link but it was ignored. I think I'd rather build the name at runtime as that means there is less scope for screw ups when the application is deployed.
Many thanks for any help, I've been tearing my hair out all day on this.
© Stack Overflow or respective owner