我需要一个自定义属性来为Weblogic中的每个服务器JVM设置。做这件事的更好方法是什么?
我知道我们可以指定如下的论据:
我的问题是如何定义参数?如何在将在JVM中部署的应用程序中使用该参数。
修改
如果我指定,-DMyArg=MyValue
在代码中,value=System.getproperty("MyValue");
这应该有效,对吗?
答案 0 :(得分:9)
编辑:如果我指定“-DMyArg = MyValue”并在代码中, 值= System.getproperty( “myvalue的”);这应该有用,对吗?
轻微的错误,你应该使用
value=System.getProperty("MyArg");
但这仅适用于启用NodeManager。如果不是这样的话,我所做的就是将它作为Java_Options之一在startWeblogic.cmd中设置
更好的是具有
行的setDomainEnv.cmdset EXTRA_JAVA_PROPERTIES=...
答案 1 :(得分:1)
在bin目录下编辑setDomainEnv.sh
找到以下行:
如果设置了USER_MEM_ARGS
环境变量,请使用它覆盖ALL MEM_ARGS
添加以下行并相应地修改值
适用于管理服务器
`if [ "${SERVER_NAME}" = "AdminServer" ] ; then
USER_MEM_ARGS="-Xms256m -Xmx256m -XX:MaxPermSize=256m"
MEM_ARGS="${USER_MEM_ARGS}"
export MEM_ARGS
fi`
对于受管服务器
`if [ "${SERVER_NAME}" != "AdminServer" ] ; then
USER_MEM_ARGS="-Xms512m -Xmx512m -XX:MaxPermSize=256m"
MEM_ARGS="${USER_MEM_ARGS}"
export MEM_ARGS
fi`
答案 2 :(得分:0)
如果你需要一个“自定义属性来为weblogic中的每个服务器JVM设置”,那么使用startWeblogic.cmd或setDomainEnv.cmd是不够的,因为它们将设置相同的值你的所有服务器。
如果未启用NodeManager,您可以做的一件事是手动编辑config.xml文件,并为每个服务器添加/编辑<arguments>
元素下的<server-start>
元素。
但是 - 不推荐这样做(见这里:http://docs.oracle.com/cd/E23943_01/web.1111/e13716/config_files.htm)。最好依靠NodeManger并使用您描述的过程。
除此之外,上述答案value=System.getProperty("MyArg");
是正确的。
答案 3 :(得分:0)
我通常为DOMAIN_HOME下的每个受管服务器创建简单的调用脚本,然后调用/ bin目录中的通用启动脚本 - 就像WebLogic自动为管理服务器创建的那样。我知道你可以用这种方式覆盖内存参数,我很确定你可以改变JVM。
以下是Windows测试脚本的示例:
cd bin
SET USER_MEM_ARGS=-Xms512m -Xmx512m
startManagedWebLogic.cmd new_ManagedServer_1 localhost:7001
我猜在UNIX中会是这样的(抱歉不太了解bash脚本):
cd bin
export USER_MEM_ARGS="-Xms512m -Xmx512m"
./startManagedWebLogic.sh new_ManagedServer_1 localhost:7001
我认为改变JVM会是这样的:
export JAVA_VENDOR="Oracle"
export USER_MEM_ARGS="-Xms512m –Xmx1g"
./startWebLogic.sh
有兴趣听到有人对此提出反馈意见。希望它可以帮助某人。 。
答案 4 :(得分:0)
您可以通过修改以下文件来实现 C:\ Oracle \ Middleware \ Oracle_Home \ user_projects \ domains \ base_domain \ bin \ startWebLogic.cmd
在我的情况下,它是域base_domain。
找到下一行并进行编辑。
@REM JAVA_OPTIONS - Java command-line options for running the server. (These
set "JAVA_OPTIONS=%JAVA_OPTIONS% -DyourVariable=value"
示例
@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
答案 5 :(得分:0)
如果您使用的是Windows,请导航至%OracleHome%\user_projects\domains\base_domain\bin
在记事本++中编辑setDomainEnv.cmd
找到设置最终JAVA_OPTIONS的行,
set JAVA_OPTIONS=%JAVA_OPTIONS%
您可以在此行上方放置客户java参数。像
set JAVA_OPTIONS=%JAVA_OPTIONS% -Dcustom.prop=value
set JAVA_OPTIONS=%JAVA_OPTIONS%
现在,如果WebLogic正在运行,请停止并重新启动管理控制台。您将能够在命令提示符或Eclipse控制台中验证您的客户Java参数启动了WebLogic,
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
现在在您的应用中,您可以通过System.getProperty("custom.prop")