JEE6 JNDI Global Name and Maven Deployment
I'm having problems with the global JNDI names of my EJB resources, which (or at least will) cause JNDI requests to fail. The project is developed in Netbeans and is a standard Maven web application. When my app is deployed to GF3.0, the app name is set to:
com.example_myapp_war_1.0-SNAPSHOT
which is good and good from the Netbeans point of view, because it guarantees uniqueness of the name, but also means that all EJBs are given global names, such as:
Java: global / com.example_myapp_war_1.0-PANORAMA / CustomerService
This will of course cause problems because every time the version changes, all the global names change (I tested this by changing the version and the names did change). The name is generated from the POM file and it is a concatenation:
<groupId>com.example</groupId>
<artifactId>myapp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
So far I've managed to just inject all the resources using @EJB, but now I need to access the EJB CustomerService from the JSF converter, so I'm doing JNDI looking 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 app is properly released and the module name changes. So the million dollar question is, how can I set the model name in maven, or how can I restore the module name so that I can programmatically build the JNDI name in runtile. I tried to set it in the web.xml file as suggested by this link, but it was ignored. I think I would prefer to create the name at runtime as it means there is less room for screws when deploying the application.
Thanks so much for any help, I've been ripping my hair out all day.
a source to share
how to set module name in maven or how to restore module name so I can program JNDI name at runtime.
Ok, as stated in the link provided, about module-name
the portable global JNDI name in EJB 3.1:
<module-name>
the default is given a name (.war or .jar) with no package extension.
So, I would configure Maven and set finalName
to not include the version in the name of the WAR:
<project>
...
<build>
<finalName>${artifactId}</finalName>
...
</build>
</project>
Not sure why NetBeans includes the package name and underscore (NetBeans does this, right?) When deploying to GlassFish, and if you can avoid it NB.
a source to share