简体   繁体   中英

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.

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.

You can do all those things with a deployment plan jar.

It looks like the content of the deployment plan jar is pushed into archive/directory tree of the application BEFORE any of the heavy lifting associated with deployment happens.

See

http://java.net/projects/glassfish/sources/svn/content/trunk/main/appserver/deployment/javaee-core/src/main/java/org/glassfish/javaee/core/deployment/DolProvider.java

and

http://java.net/projects/glassfish/sources/svn/content/trunk/main/appserver/deployment/dol/src/main/java/com/sun/enterprise/deployment/archivist/Archivist.java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM