Best way to set environment variables when starting WebLogic

In Oracle WebLogic, what is the best way to set an environment variable so that your code can access it? We have third-party applications with WebLogic that are looking for an environment variable.

Note. We run our managed servers using Node Manager.

I would prefer to be able to install it somewhere in the domain configuration, as on the "Start Server" tab in the admin console, but there seems to be no suitable place for this.

The only way to do this is

  1. Edit bin/setDomainEnv.sh to export the environment variable
  2. Modify nodemanager.properties to have StartScriptEnabled=true

This forces NodeManager to use <ms_home>/bin/startManagedWebLogic.sh , which is the source of setDomainEnv.sh , and they will be received when NodeManager starts. But you must also do this on every machine.

I wonder if there is a cleaner way to do this than to delve into Oracle startup scripts.

+8
java environment-variables weblogic startup
source share
1 answer

If you know for sure that none of the common frameworks are used, for example, the Spring Framework, and you have code that strictly searches for environment variables, then you must set environment variables outside any of the usual configuration files before the Java process starts that awaits him. After starting the Java process, the environment variables are read-only and are final for the process.

Note. . If you need environment variables for the whole system, use / etc / profile, / etc / bash_profile, / etc / environment, etc. Keep in mind that setting variables to these global locations requires restarting Node Manager from a new login. You do not need to reboot, but profile / environment files usually only exit when you log in.

For applications in only one domain or node, environment variables must be in startup scripts for the server (s). Editing setDomainEnv. [Sh | cmd] or run (managed) Weblogic. [Sh | cmd] is the best option for setting WebLogic environment variables.

However, if the application uses Spring, the system properties and environment variables are combined. System properties are very welcome and easier to maintain and control.

Link: What is best suited for setting java, -D, or System.setProperty () system properties?

Weblogic Domain Environment Variables

One of the places to set both system properties and environment variables is to edit the script domain environment used to run all nodes or servers that use the same installation and the WebLogic server domain. Inside <weblogic_domain> /bin/setDomainEnv.sh(setDomainEnv.cmd on windows), for environment variables, just add them near the top and add comments to document their use.

  export CUSTOM_VAR="test" # UNIX comment to describe environment variable. 

For system properties, you can add command line arguments that will be added to each server by adding a line for EXTRA_JAVA_PROPERTIES at the top of the file next to the WL_HOME definition, but after functions and comments.

  EXTRA_JAVA_PROPERTIES="-Denv=TEST" export EXTRA_JAVA_PROPERTIES WL_HOME="/appl/oracle/middleware/wls/12.1.2.0.0/wlserver" export WL_HOME 

Weblogic Node Special Environment Variables

If you need different environment variables for each Node launched by the same Node manager, you will have to configure startup scripts a bit. In this case, edit <weblogic_domain> / bin / startManagedWeblogic. [sh | cmd] and paste some scripting logic after _export SERVER_NAME_. This way you can manage settings based on SERVER_NAME etc.

Tip. Windows environment variables are not case sensitive using System.getenv (..).

+11
source share

All Articles