3

This is a follow-up to a question I posted a while back: "Can I use a single WAR in multiple environments?". I was able to create a single-war solution in Tomcat, but now we are migrating our app to JBoss 4.2 and I can't figure out how to set up global environment variables.

In Tomcat 6 this was pretty straightforward: I simply put the following snippet in tomcat/conf/Catalina/myappname.xml:

<Context ...>
   <Environment name="TARGET_ENV" value="DEV" type="java.lang.String" override="false"/>
</Context>

Then in my app I was able to resolve the environment name with the following:

Context context = (Context) InitialContext().lookup("java:comp/env");
String targetEnvironment = (String) context.lookup("TARGET_ENV");

The problem is that I can't find out where/how to place global variables in JBoss. I've tried putting the <Environment> tag in the following files to no avail:

  • server/all/deploy/jboss-web.deployer/context.xml
  • server/default/deploy/jboss-web.deployer/context.xml

I know that I can put environment variables in my app's web.xml but that defeats the purpose of having a unified war - I'd still need custom .war's for dev, qa and prod.

I'm a JBoss newbie so if there's any additional information that would help just let me know and I'll append to this question.

Community
  • 1
  • 1
NobodyMan
  • 2,381
  • 4
  • 29
  • 35

1 Answers1

1

I use somehing similar to PropertiesService for database url, and other environment related things.

Therefore I'm relieved from the burden to provide different environment related atrifacts.

stacker
  • 68,052
  • 28
  • 140
  • 210
  • Properties service is an option, and it could work - but isn't it jboss specific? It'd be nice to have a .ar that could potentially work in jboss *and* netbeans without modification to the .war itself. Possible? – NobodyMan Jun 09 '10 at 20:02
  • I developed a comparable service (resolving ${variables}) myself, the property files I place somewhere in classpath, therefore I don't face issues with dependencies on a specific application-server. – stacker Jun 11 '10 at 11:21
  • On "external properties in JBOSS" two questions: 1) Do you check-in the configuration file to your source control system? 2) How does the application know which configuration to use (DEV, TEST, UAT, PROD)? – Dchucks Aug 11 '10 at 19:00