Search code examples
javajakarta-eeglassfishjava-ee-6glassfish-3

Glassfish: modify deployment descriptors for EAR during deployment


After several days of searching, trying and head-banging, I post this question to SO although it seems to be answered already.

Here is the scenario: I have an EAR application containing (for the moment) one WAR and one EJB module. The EJB module uses JPA (persistence.xml) and some Stateless Session Beans are exposed via Web Services. The web services use Basic authentication with a jdbc realm. The web module uses form authentication with the same realm.

The requirement: I need to be able to deploy this application either on different servers (dev/test/prod) or on the same server (or cluster) with different deployment descriptors. The deployment settings that need to be different in each application instance are:

  • The jta-data-source in persistence.xml
  • The realm-name in web.xml
  • The javax.faces.PROJECT_STAGE in web.xml
  • The webservice-endpoint\endpoint-address-uri and login-config\realm in glassfish-ejb-jar.xml
  • The context-root in application.xml (i could move it to web.xml if it made any difference, see below)
  • The realm in glassfish-application.xml

During my research, I managed the following:

  • I can override the javax.faces.PROJECT_STAGE using asadmin set-web-context-param
  • I can override all settings in glassfish-ejb-jar.xml using a deployment plan during asadmin deploy
  • The same applies for glassfish-application.xml
  • I can probably override context-root during asadmin deploy (I don't know how would this work with more than one web modules in the EAR)

So far so good. This leaves me with the following problems:

  • How can I easily modify the the realm-name in web.xml?
  • How can I easily modify the jta-data-source in persistence.xml?

By easily I mean during deployment or using something similar to a deployment plan jar. Maintaining multiple copies of ejb.jar or war just with a modified .xml file is not an option.

Just to be clear, the need is to have different databases (either in different stages of development or for different customers) using the same application. The application uses one persistence-unit but it needs to point to different databases (hence the jta-data-source). The realm is a jdbc realm (on the same database) that also needs to be different per application instance.

Any help or pointer would be greatly appreciated.


Solution

  • Have you thought about preparing templates for the deployment descriptors, and populating them with value from property file during build? If you are using ant, you can use the expandproperties filter.