Best way to set environmental variables in WebLogic startup

后端 未结 1 1282
迷失自我
迷失自我 2021-02-05 23:57

In Oracle WebLogic, what is the best way to set an environmental variable so that it can be accessed by your code? We have third-party apps running WebLogic that look for an en

相关标签:
1条回答
  • 2021-02-06 00:43

    If you know for certain that none of the common frameworks are in use, like the Spring Framework, and you have code that strictly looks for environment variables, then you must set the environment variables outside of any of the usual configuration files, before the Java process that will be expecting it, is started. Once the Java process is started, environment variables are read-only and final for that process.

    Note: If you need Environment Variables for the entire system, use /etc/profile, /etc/bash_profile, /etc/environment, etc. Keep in mind, that setting the variables in these global locations requires that you restart the Node Manager from a fresh login. You do not need to reboot, but profile/environment files are usually only sourced on login.

    For apps within just one domain or node, environment variables should be in the startup scripts for the server(s). Editing setDomainEnv.[sh|cmd] or start(Managed)Weblogic.[sh|cmd], is the best option for setting WebLogic environment variables.

    However, if the app is using Spring, system properties and environment variables are combined. System properties are highly encouraged and easier to maintain and control.

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

    Weblogic Domain environment variables

    One of the places to set both system properties or environment variables, is to edit the domain environment script used to start all nodes or servers that share the same WebLogic server installation and 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 every server by adding a line for EXTRA_JAVA_PROPERTIES, near the top of the file, near the WL_HOME definition, but after the 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-specific environment variables

    If you need different Environment Variables for each node that is started up by the same Node Manager, you will have to customize the startup scripts a little more. In that case, edit the < weblogic_domain >/bin/startManagedWeblogic.[sh|cmd] and insert some scripting logic after _export SERVER_NAME_. This way, you can drive your settings based on SERVER_NAME, etc.

    Tip: Windows Environment Variables are not case-sensitive with System.getenv(..).

    0 讨论(0)
提交回复
热议问题