Charlee Chitsuk
Charlee Chitsuk

Reputation: 9069

How to configure the glassfish domain.xml by using the OS environment variable?

I would like to pass the environment variable to the glassfish domain.xml as the following:-

<jvm-options>-DMY_FILE=file:///${MY_HOME}/a.txt</jvm-options>

${MY_HOME} is an environment variable.

I'm not sure if this is possible or not. Could you please help to advise further? Thank you very much for your help in advance. I'm looking forward to hearing from you soon.

Regards,

Charlee Ch.

Upvotes: 2

Views: 4761

Answers (2)

helvete
helvete

Reputation: 2673

In case you are running Payara (> 4.1.2.172) server it is now possible to utilize the environment variables.

I am using excerpts from the official documentation:

Variable references can be used like this:

<domain log-root="${com.sun.aas.instanceRoot}/${ENV=STAGE_NAME}/logs">

Variable references can be used in these places:

Domain configuration

  • domain.xml (inside attribute values or inside text nodes that contain a configuration value)
  • logging.properties (inside property values)

Package descriptors:

  • web.xml / glassfish-web.xml
  • ejb-jar.xml / glassfish-ejb-jar.xml
  • application.xml / glassfish-application.xml
  • glassfish-resources.xml

Framework descriptors:

  • persistence.xml
  • faces-config.xml

In the annotations:

  • @EJB
  • @WebService
  • @Stateless
  • @Stateful
  • @Singleton
  • @ActivationConfigProperty
  • @DataSource
  • @WebServlet

Other

  • In JNDI lookups inside an application
  • In pre and post boot command files. [Since Payara Server 4.1.2.174]
  • In JVM Options. [Since Payara Server 4.1.2.182 and 5.182]
  • In payara-expression-config.properties file [Since Payara Server 5.20.0].

Upvotes: 1

Oliver
Oliver

Reputation: 4183

You can only use Java system properties (-D) to define variables outside of domain.xml.

See Oracle GlassFish Server 3.0.1 Domain File Format Reference for details.

If you need to change your settings regulary better you write an small wrapper script which calls asadmin to change specific parts of the configuration and starts/restarts GlassFish afterwards.

Upvotes: 2

Related Questions