4

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?

ronalchn
  • 12,225
  • 10
  • 51
  • 61
talya.gendler
  • 43
  • 1
  • 1
  • 5

1 Answers1

3

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.

Mani
  • 965
  • 6
  • 10
  • How can i use the startWebLogic.cmd to determine which managed server will receive this value? I do not want this to be set for all managed servers in my domain, only for a specific sub set of them. – talya.gendler Sep 28 '12 at 07:59
  • To be more specific, what I need is a way to set this JAVA_OPTION for any subset of the servers in the domain, possibly distributed ones. The subset is determined by the user's input and is not known to me in advance. – talya.gendler Sep 28 '12 at 08:48
  • And you set the ServerStart arguments dynamically for the servers (input by user) during the domain creation? – Mani Sep 28 '12 at 10:48
  • The domain pre exists, created by the user. To install my utility, he supplies as input the names of the servers he is interested in. Then, what I would like to do, is edit the server start arguments (JAVA_OPTIONS) for each of those servers. Each one in the same manner - adding the property that relies on an env. variable on any of the managed servers, some of which may be distributed and on remote machines. – talya.gendler Sep 28 '12 at 14:48
  • I have updated the answer (using WLST). Let me know what your current utility uses (Is it an automation script that opens AdminConsole and updates serverstart arguments?). – Mani Sep 28 '12 at 17:36
  • also I didn't try executing the script, so there could be some syntax errors. Please have a look – Mani Sep 28 '12 at 17:38
  • My current utility is actually some script that edits the config.xml file. I was hoping to avoid having to run it on every machine. Also, if i edit the config.xml on a distributed machine, it will just get overridden by the admin server's node manager. In this solution, will the local changes that the node manager of each server performs be persisted correctly without been overridden? I will try this script out and let you know how it goes. – talya.gendler Sep 28 '12 at 18:05
  • Also, still wondering about: "using double quotes? what if i have to reference a folder with spaces in it's name?" This could happen on any given machine easily – talya.gendler Sep 28 '12 at 18:08
  • Hmm. I haven't thought about the config.xml overriden by NM. You are correct following this approach will have the risk of config.xml overriden with the one present on the Base/AdminServer host. But, in order to get the host specific environment variable value of "USERPROFILE" the solution has to be at the every host level. I think we need to fallback to the startWebLogic.cmd approach. I will append to the answer in few mins. – Mani Sep 28 '12 at 18:18
  • On the spaces in JVM argument value : There should be some escape character I believe, I don't know what that is though. – Mani Sep 28 '12 at 18:19
  • Mani, thank you for your help :) A thought - If we found how to escape the quotes (i've tried numerous solutions and spent a lot of Google time but with no success), then wouldnt that be easier than utilizing wlst? Do you also think that would cause evaluation to happen on runtime? – talya.gendler Sep 28 '12 at 18:36
  • I don't think so, but you give a try by having the jar in a directory whose patch doesn't have space, create a environment variable for this new directory and use that in the ServerStart args and see if WLS is evaluating it during runtime – Mani Sep 28 '12 at 18:47
  • The first option sounds like a great solution! Is it possible you meant to edit the startMangaedWebLogic script and not the setDomainEnv script? In the setDomainEnv the only name used is the admin server: 'if "%SERVER_NAME%"=="" ( set SERVER_NAME=AdminServer )' But the startMangaedWebLogic contains the mentioned export. Is this the correct script to edit to make sure all managed (and distributed) servers are affected? – talya.gendler Sep 28 '12 at 18:55
  • setDomainEnv.sh is called from startWebLogic.sh (NM uses). Also if you use startManagedWebLogic.sh then it will still work because it will export SERVER_NAME and then at the end call startWebLogic.sh and this will in turn call setDomainEnv.sh, so that way for a managed server the SERVER_NAME would have been set already so it wouldn't go into the if loop. Oh, wait I think that "new code" should be inserted after the if loop in setDomainEnv.sh. – Mani Sep 28 '12 at 19:22
  • Ok, i just tried this out with success :) When i changed it in the startManagedWebLogic.sh it did not work. But in the startWebLogic.sh it did. Appending the option: 'set JAVA_OPTIONS=%JAVA_OPTIONS% -DMy.prop:"%USERPROFILE%\foo\bar.jar' worked for a managed server. Still need to test for distributed and probably fully grok the cycle of scripts as you explained above. Thanks! :) – talya.gendler Sep 28 '12 at 19:34
  • 1
    Ok. That's great to hear. I didn't explain the scripts cycle clearly enough I guess. Hope you understood how it works. Basically its like this : startManagedWebLogic.sh -> startWebLogic.sh -> setDomainEnv.sh . Any variable's values with "export or set" used will be carried over. – Mani Sep 28 '12 at 19:39
  • Not quite clear then why it did not work from startManagedWebLogic.sh I will retry that, but as long as i now know it can be done, i guess finding the correct script is now the easy part. Tks again! – talya.gendler Sep 28 '12 at 19:42
  • that's because when NM is used for start the script cycle start from startWebLogic.sh. startManaged is ignored. – Mani Sep 29 '12 at 05:46