简体   繁体   中英

Custom arguments to set in Weblogic JVM

I need a custom property to set per each server JVM in Weblogic. What is the better approach doing it?

I know we can specify the argments like below:

  1. In the Domain Structure pane, expand the Servers node.
  2. Click the name of the server that you want to configure.
  3. In the right pane, click Server Start.
  4. Select Lock & Edit.
  5. In the Arguments text box, provide the JVM options. After inserting your options, click Save. Then click Activate Changes.
  6. Restart the server so that the new settings are used.

My question is how exactly the argument is defined? How to use that argument inside the application that will be deployed inside that JVM.

Edit

If i specify, -DMyArg=MyValue and in the code, value=System.getproperty("MyValue"); this should work, right?

Edit: if i specify, "-DMyArg=MyValue" and in the code, value=System.getproperty("MyValue"); this should work, right?

Slight mistake, you should use

value=System.getProperty("MyArg");

This however only works with NodeManager enabled. If that's not the case, what I do is to set it in the startWeblogic.cmd as one of the Java_Options

Even better is the setDomainEnv.cmd which has lines for

set EXTRA_JAVA_PROPERTIES=...

Under bin directory edit setDomainEnv.sh find the below line:

If USER_MEM_ARGS the environment variable is set, use it to override ALL MEM_ARGS add the below lines and modify the values accordingly

For Admin Server

`if [ "${SERVER_NAME}" = "AdminServer" ] ; then
USER_MEM_ARGS="-Xms256m -Xmx256m -XX:MaxPermSize=256m"
MEM_ARGS="${USER_MEM_ARGS}"
export MEM_ARGS
fi`

For Managed Server

`if [ "${SERVER_NAME}" != "AdminServer" ] ; then
USER_MEM_ARGS="-Xms512m -Xmx512m -XX:MaxPermSize=256m"
MEM_ARGS="${USER_MEM_ARGS}"
export MEM_ARGS
fi`

If you need a " custom property to set per each server JVM in weblogic", then using the startWeblogic.cmd or setDomainEnv.cmd won't be enough as they will set the same value for all of your servers.

One thing you could do if the NodeManager is not enabled is manually edit the config.xml file and add/edit the <arguments> element under the <server-start> element for each server.

But - this is not recommended (see here: http://docs.oracle.com/cd/E23943_01/web.1111/e13716/config_files.htm ). Much better to rely on the NodeManger and use the procedure you described.

Other than that the above answer value=System.getProperty("MyArg"); is correct.

I usually create simple call scripts for each managed server under DOMAIN_HOME, that in turn call the generic start scripts in the /bin directory - like the one that WebLogic automatically creates for the Admin Server. I know you can override memory arguments this way and I'm pretty sure you can change JVM.

Here's an example of a tested script for Windows:

cd bin
SET USER_MEM_ARGS=-Xms512m -Xmx512m
startManagedWebLogic.cmd new_ManagedServer_1 localhost:7001

which I guess in UNIX would be something like this (sorry don't know much about bash scripts):

cd bin
export USER_MEM_ARGS="-Xms512m -Xmx512m"
./startManagedWebLogic.sh new_ManagedServer_1 localhost:7001

I think to change the JVM it would be something like:

export JAVA_VENDOR="Oracle"
export USER_MEM_ARGS="-Xms512m –Xmx1g"
./startWebLogic.sh

Would be interested to hear anyone's feedback on this. Hope it helps someone . . .

You can do it by modifying the following file C:\\Oracle\\Middleware\\Oracle_Home\\user_projects\\domains\\base_domain\\bin\\startWebLogic.cmd

in my case it is the domain base_domain.

find the next line and edit.

@REM JAVA_OPTIONS   - Java command-line options for running the server. (These
set "JAVA_OPTIONS=%JAVA_OPTIONS% -DyourVariable=value"

Example

@ECHO OFF

@REM WARNING: This file is created by the Configuration Wizard.
@REM Any changes to this script may be lost when adding extensions to this configuration.

SETLOCAL

@REM --- Start Functions ---

GOTO :ENDFUNCTIONS

:stopAll
    @REM We separate the stop commands into a function so we are able to use the trap command in Unix (calling a function) to stop these services
    if NOT "X%ALREADY_STOPPED%"=="X" (
        exit /b
    )
    @REM STOP DERBY (only if we started it)
    if "%DERBY_FLAG%"=="true" (
        echo Stopping Derby server...
        call "%WL_HOME%\common\derby\bin\stopNetworkServer.cmd"  >"%DOMAIN_HOME%\derbyShutdown.log" 2>&1 

        echo Derby server stopped.
    )

    set ALREADY_STOPPED=true
GOTO :EOF

:generateClassList
    set JAVA_OPTIONS=%JAVA_OPTIONS% -Xshare:off -XX:+UnlockCommercialFeatures -XX:+IgnoreEmptyClassPaths -XX:DumpLoadedClassList=%APPCDS_CLASS_LIST% -XX:+UseAppCDS
GOTO :EOF

:useArchive
    set JAVA_OPTIONS=%JAVA_OPTIONS% -XX:+UnlockCommercialFeatures -Xshare:auto -XX:+UseAppCDS -XX:+IgnoreEmptyClassPaths -XX:SharedArchiveFile=%APPCDS_ARCHIVE% -showversion
    set USING_SHOWVERSION=true
GOTO :EOF


:ENDFUNCTIONS
ECHO HOLA.........................................................................
@REM --- End Functions ---

@REM *************************************************************************
@REM This script is used to start WebLogic Server for this domain.
@REM 
@REM To create your own start script for your domain, you can initialize the
@REM environment by calling @USERDOMAINHOME\setDomainEnv.
@REM 
@REM setDomainEnv initializes or calls commEnv to initialize the following variables:
@REM 
@REM BEA_HOME       - The BEA home directory of your WebLogic installation.
@REM JAVA_HOME      - Location of the version of Java used to start WebLogic
@REM                  Server.
@REM JAVA_VENDOR    - Vendor of the JVM (i.e. BEA, HP, IBM, Sun, etc.)
@REM PATH           - JDK and WebLogic directories are added to system path.
@REM WEBLOGIC_CLASSPATH
@REM                - Classpath needed to start WebLogic Server.
@REM PATCH_CLASSPATH - Classpath used for patches
@REM PATCH_LIBPATH  - Library path used for patches
@REM PATCH_PATH     - Path used for patches
@REM WEBLOGIC_EXTENSION_DIRS - Extension dirs for WebLogic classpath patch
@REM JAVA_VM        - The java arg specifying the VM to run.  (i.e.
@REM                - server, -hotspot, etc.)
@REM USER_MEM_ARGS  - The variable to override the standard memory arguments
@REM                  passed to java.
@REM PRODUCTION_MODE - The variable that determines whether Weblogic Server is started in production mode.
@REM DERBY_HOME - Derby home directory.
@REM DERBY_CLASSPATH
@REM                - Classpath needed to start Derby.
@REM 
@REM Other variables used in this script include:
@REM SERVER_NAME    - Name of the weblogic server.
set "JAVA_OPTIONS=%JAVA_OPTIONS% -DUPLOAD_HOME=C:\files"
@REM JAVA_OPTIONS   - Java command-line options for running the server. (These
@REM                  will be tagged on to the end of the JAVA_VM and
@REM                  MEM_ARGS)
@REM PROXY_SETTINGS - These are tagged on to the end of the JAVA_OPTIONS. This variable is deprecated and should not
@REM                  be used. Instead use JAVA_OPTIONS
@REM 
@REM For additional information, refer to "Administering Server Startup and Shutdown for Oracle WebLogic Server"
@REM *************************************************************************

set SCRIPTPATH=%~dp0
set SCRIPTPATH=%SCRIPTPATH%
for %%i in ("%SCRIPTPATH%") do set SCRIPTPATH=%%~fsi


@REM Call setDomainEnv here.

set DOMAIN_HOME=C:\Oracle\Middleware\Oracle_Home\user_projects\domains\base_domain
for %%i in ("%DOMAIN_HOME%") do set DOMAIN_HOME=%%~fsi

call "%DOMAIN_HOME%\bin\setDomainEnv.cmd" %*

set SAVE_JAVA_OPTIONS=%JAVA_OPTIONS%

set SAVE_CLASSPATH=%CLASSPATH%

set TMP_UPDATE_SCRIPT=%TMP%\update.cmd


@REM Start Derby

set DERBY_DEBUG_LEVEL=0

if "%DERBY_FLAG%"=="true" (
    call "%WL_HOME%\common\derby\bin\startNetworkServer.cmd"  >"%DOMAIN_HOME%\derby.log" 2>&1 

)

set JAVA_OPTIONS=%SAVE_JAVA_OPTIONS%

@REM In order to use resource consumption management policies or to get partition's resource consumption metrics, uncomment the following JAVA_OPTIONS

set #JAVA_OPTIONS=-XX:+UnlockCommercialFeatures -XX:+ResourceManagement -XX:+UseG1GC %SAVE_JAVA_OPTIONS%

set SAVE_JAVA_OPTIONS=

set CLASSPATH=%SAVE_CLASSPATH%

set SAVE_CLASSPATH=

if "%PRODUCTION_MODE%"=="true" (
    set WLS_DISPLAY_MODE=Production
) else (
    set WLS_DISPLAY_MODE=Development
)

if NOT "%WLS_USER%"=="" (
    set JAVA_OPTIONS=%JAVA_OPTIONS% -Dweblogic.management.username=%WLS_USER%
)

if NOT "%WLS_PW%"=="" (
    set JAVA_OPTIONS=%JAVA_OPTIONS% -Dweblogic.management.password=%WLS_PW%
)

if NOT "%MEDREC_WEBLOGIC_CLASSPATH%"=="" (
    if NOT "%CLASSPATH%"=="" (
        set CLASSPATH=%CLASSPATH%;%MEDREC_WEBLOGIC_CLASSPATH%
    ) else (
        set CLASSPATH=%MEDREC_WEBLOGIC_CLASSPATH%
    )
)

if "%GENERATE_CLASS_LIST%"=="true" (
    CALL :generateClassList
)

if "%USE_ARCHIVE%"=="true" (
    CALL :useArchive
)

echo .

echo .

echo JAVA Memory arguments: %MEM_ARGS%

echo .

echo CLASSPATH=%CLASSPATH%

echo .

echo PATH=%PATH%

echo .

echo ***************************************************

echo *  To start WebLogic Server, use a username and   *

echo *  password assigned to an admin-level user.  For *

echo *  server administration, use the WebLogic Server *

echo *  console at http:\\hostname:port\console        *

echo ***************************************************

@REM START WEBLOGIC

if NOT "%USE_JVM_SYSTEM_LOADER%"=="true" (
    set LAUNCH_ARGS=-cp %WL_HOME%\server\lib\weblogic-launcher.jar -Dlaunch.use.env.classpath=true
)

if "%USING_SHOWVERSION%"=="true" (
    echo starting weblogic with Java version:
    %JAVA_HOME%\bin\java %JAVA_VM% -version
)

if "%WLS_REDIRECT_LOG%"=="" (
    echo Starting WLS with line:
    echo %JAVA_HOME%\bin\java %JAVA_VM% %MEM_ARGS% %LAUNCH_ARGS% -Dweblogic.Name=%SERVER_NAME% -Djava.security.policy=%WLS_POLICY_FILE% %JAVA_OPTIONS% %PROXY_SETTINGS% %SERVER_CLASS%
    %JAVA_HOME%\bin\java %JAVA_VM% %MEM_ARGS% %LAUNCH_ARGS% -Dweblogic.Name=%SERVER_NAME% -Djava.security.policy=%WLS_POLICY_FILE% %JAVA_OPTIONS% %PROXY_SETTINGS% %SERVER_CLASS%
) else (
    echo Redirecting output from WLS window to %WLS_REDIRECT_LOG%
    %JAVA_HOME%\bin\java %JAVA_VM% %MEM_ARGS% %LAUNCH_ARGS% -Dweblogic.Name=%SERVER_NAME% -Djava.security.policy=%WLS_POLICY_FILE% %JAVA_OPTIONS% %PROXY_SETTINGS% %SERVER_CLASS%  >"%WLS_REDIRECT_LOG%" 2>&1 
)

IF ERRORLEVEL 86 IF NOT ERRORLEVEL 87 (set shutDownStatus=86) ELSE (IF ERRORLEVEL 88 IF NOT ERRORLEVEL 89 ( set shutDownStatus=88 ) )


CALL :stopAll

popd

IF EXIST %TMP_UPDATE_SCRIPT% (set fileExists=true) ELSE (set fileExists=false)


if "%shutDownStatus%"=="86" (
    if "%fileExists%"=="true" (
        echo Calling %TMP_UPDATE_SCRIPT%

        cd %TMP:~0,2%
        cd %TMP%
        call %TMP_UPDATE_SCRIPT%
        IF ERRORLEVEL 42 IF NOT ERRORLEVEL 43 (set ustatus=42 )

        @REM restoring the original env before unsetting JAVA_HOME
        @REM in order to unset any JAVA_HOME that was passed in from domainEnv
        if "%ustatus%"=="42" (
            set JAVA_HOME=
        )
    ) else (
        echo ERROR! %TMP_UPDATE_SCRIPT% did not exist
    )
    @REM Call the same script path that was supplied in order to restart ourselves
    @REM restoreOrigEnv will go here

    call "%SCRIPTPATH%\startWebLogic.cmd"

) else (
    if "%shutDownStatus%"=="88" (
        @REM restoreOrigEnv will go here

        call "%SCRIPTPATH%\startWebLogic.cmd"

    )
)

@REM Exit this script only if we have been told to exit.

if "%doExitFlag%"=="true" (
    exit
)



ENDLOCAL

If you are using Windows, navigate to %OracleHome%\\user_projects\\domains\\base_domain\\bin

Edit the setDomainEnv.cmd in note pad++

Find the line where the final JAVA_OPTIONS are set,

set JAVA_OPTIONS=%JAVA_OPTIONS%

You can have your customer java arguments above this line. Something like,

set JAVA_OPTIONS=%JAVA_OPTIONS% -Dcustom.prop=value

set JAVA_OPTIONS=%JAVA_OPTIONS%

Now if you WebLogic is running please stop and restart the Admin Console. You will be able to verify in the command prompt or eclipse console that WebLogic is started with your customer java args,

Starting WLS with line:
C:\PROGRA~1\Java\JDK18~1.0_1\bin\java -server   
-Xms256m -Xmx512m -XX:CompileThreshold=8000 
BLA BLA BLA 
-Dweblogic.home=C:\ORACLE~1\MIDDLE~1\ORACLE~1\wlserver\server 
-Dcustom.prop=value  
weblogic.Server

Now in your appliation you can access it by System.getProperty("custom.prop")

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