2 Replies Latest reply on Oct 28, 2014 10:02 AM by Eduardo Martins

    Override JNDI names in persistence.xml and @resource annotation

    Paul Holding Newbie

      I have a Java EE 7 application that I am developing for use with both GlassFish and WildFly, but I have discovered that both application servers use a slightly different format for specifying JNDI names.

       

      In GlassFish the persistence.xml file references the data source jdbc/myDataSouce, but in WildFly the data source needs to be java:/jdbc/myDataSource.The same is also true for classes that are annotated with @Resource. In GlassFish the annotation for a class using JavaMail would be @Resource(name = "mail/myMailSession"), but to deploy onto WildFly this would need to be @Resource(name = "java:mail/myMailSession").

       

      The only solution I've got at present is using Maven to create two different releases of the EAR file, with one EAR file containing a persistence.xml file with the data source jdbc/myDataSouce for use with GlassFish, and the second EAR file containing a persistence.xml file with the data source java:/jdbc/myDataSource for use with WildFly. Unfortunately, I haven't found a solution for the @Resource annotation.

       

      I'm assuming the solution may be to create a jboss-app.xml file or a jboss-ejb3.xml file, but as I'm new to WildFly I haven't been able to spot anything in documentation that allows the JNDI names to be overridden.

       

      My question is does WildFly provide any capability to override the JNDI names specified in the persistence.xml file and classes with the @resource annotation?

       

      Many Thanks

       

      Paul