WebLogic - Using environment variable / double quotes in “Arguments” in “Server Start”

有些话、适合烂在心里 提交于 2019-12-07 11:27:37

问题


I have an admin server, NodeManager, and 1 managed server, all on the same machine. I am trying to enter something similar to this to the arguments field in the Server Start tab:

-Dmy.property=%USERPROFILE%\someDir\someJar.jar

But when the managed server is started it throws this exception:

Error opening zip file or JAR manifest missing : %USERPROFILE%\someDir\someJar.jar

It appears that the environment variable is not being translated into it's value. It is just passed on to the managed server as plain-text. I tried surrounding the path with double quotes (") but the console validates the input and does not allow this: "Arguments may not contain '"'"

Even editing the config.xml file manually cannot work, as the admin server fails to startup after this:

<Critical> <WebLogicServer> <BEA-000362> <Server failed. Reason: [Management:141266]Parsing failure in config.xml: java.lang
.IllegalArgumentException: Arguments may not contain '"'.>

I also tried using %20 to no avail, it is just passed as %20.

I thought that perhaps this had something to do with the spaces in the value of %USERPROFILE% (which is "C:\documents and settings.."), but the same thing happens with other env. variables which point to other directories with no spaces.

My question:

Is there any supported way of :

  1. using double quotes? what if i have to reference a folder with spaces in it's name?

  2. reference an environment variable? What if i have to rely on it's value for distributed servers where i do not know in advance the variable's value?


回答1:


Edit based on comments:

Approach 1:

  1. Open setDomainEnv.cmd and search for export SERVER_NAME in Linux or for set SERVER_NAME in Windows. Skip to next to next line (i.e skip current and the next line)
  2. On the current line, insert:

    customServerList="server1,server2" #this serverList should be taken as input
    isCurrServerCustom=$(echo ${customServerList} | tr ',' '\n' | grep ${SERVER_NAME} | wc -l)
    if [ $isCurrServerCustom -gt 0 ]; then
       # add customJavaArg
       JAVA_OPTIONS="-Dmy.property=${USERPROFILE}/someDir/someJar.jar"
    fi
    
  3. Save the setDomainEnv.sh file and re-start servers

Note that I have only given logic for Linux , for Windows similar logic can be used but with batch scripting syntax.

Approach 2:

Assuming domain is already installed and user provides the list of servers to which the JVM argument -Dmy.property need to be added. Jython script (use wlst.sh to execute). WLST Reference.

Usage: wlst.sh script_name props_file_location

import os
from java.io import File
from java.io import FileInputStream

# extract properties from properties file.
print 'Loading input properties...'

propsFile       = sys.argv[1]
propInputStream = FileInputStream(propsFile)
configProps     = Properties()
configProps.load(propInputStream)
domainDir       = configProps.get("domainDir")

# serverList in properties file should be comma seperated
serverList      = configProps.get("serverList")

# The current machine's logical name as mentioned while creating the domain has to be given. Basically the machine name on which NM for current host is configured on.
# This param may not be required as an input if the machine name is configured as same as the hostname , in which case , socket module can be imported and socket.getHostName can be used.
currMachineName = configProps.get("machineName")
jarDir          = os.environ("USERPROFILE")
argToAdd        = '-Dmy.property=' + jarDir + File.separator + 'someDir' + File.separator + 'someJar.jar'
readDomain(domainDir)
for srvr in serverList.split(",") :
    cd('/Server/' + srvr)
    listenAddr = get('ListenAddress')
    if listenAddr != currMachineName :
        # Only change current host's servers
        continue
    cd('/Server/' + srvr + '/ServerStart/' + srvr)
    argsOld = get('Arguments')
    if argsOld is not None :
        set('Arguments', argsOld + ' ' + argToAdd)
    else:
        set('Arguments', argToAdd)
updateDomain()
closeDomain()
# now restart all affected servers (i.e serverList)
# one way is to connect to adminserver and shutdown them and then start again

Script has to be run from all hosts where the managed servers are going to be deployed in order to have the host specific value of "USERPROFILE" in the JVM argument.

BTW, to answer your question in a line : looks like the JVM arguments have to be supplied with the literal text eventually. But looks like WLS doesn't translate the environment variables if provided as JVM arguments. It gives an impression that it is translating when its done from startWebLogic.cmd (ex: using %DOMAIN_HOME% etc.) but its the shell/cmd executor that translates and then starts the JVM.



来源:https://stackoverflow.com/questions/12629395/weblogic-using-environment-variable-double-quotes-in-arguments-in-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!