title: JEE6 Global JNDI Name and Maven Deployment
body: <p>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:</p>
  
  <p>com.example_myapp_war_1.0-SNAPSHOT</p>
  
  <p>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:</p>
  
  <p>java:global/com.example_myapp_war_1.0-SNAPSHOT/CustomerService</p>
  
  <p>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:</p>
  
  <pre><code>&lt;groupId&gt;com.example&lt;/groupId&gt;
  &lt;artifactId&gt;myapp&lt;/artifactId&gt;
  &lt;packaging&gt;war&lt;/packaging&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>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 <a href="http://blogs.oracle.com/MaheshKannan/entry/portable_global_jndi_names" rel="nofollow noreferrer">module name</a> 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.</p>
  
  <p>Many thanks for any help, I've been tearing my hair out all day on this.</p>