WebLogic - 在“服务器启动”中使用环境变量/双引号的“参数”

4
我有一个管理员服务器、NodeManager和1个托管的服务器,都在同一台机器上。 我试图输入类似于以下内容到“服务器启动”选项卡中的参数字段:
-Dmy.property=%USERPROFILE%\someDir\someJar.jar

但是当管理服务器启动时,它会抛出以下异常:

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

看起来环境变量没有被转换成它的值。它只是作为纯文本传递给管理服务器。 我尝试用双引号(")将路径括起来,但控制台会验证输入并不允许此操作:"Arguments may not contain '"'"
即使手动编辑config.xml文件也无法解决问题,因为在这种情况下管理员服务器启动失败。
<Critical> <WebLogicServer> <BEA-000362> <Server failed. Reason: [Management:141266]Parsing failure in config.xml: java.lang
.IllegalArgumentException: Arguments may not contain '"'.>

我也尝试使用 %20,但无济于事,它只是被传递为 %20。

我认为这可能与 %USERPROFILE% 的值(即“C:\documents and settings..”)中的空格有关,但其他指向没有空格的其他目录的环境变量也会出现相同情况。

我的问题:

是否有任何支持的方法:

  1. 使用双引号?如果我需要引用一个带有空格的文件夹怎么办?

  2. 引用环境变量?如果我必须依赖它的值来分布式服务器,在预先不知道变量值的情况下该怎么做?


你在Windows上运行吗? - Jeff West
是的,我是。感谢Jeff指出,我本意是这样说的。 我还没有尝试在Linux上使用相同的${VARIABLE_NAME},我只能假设它会有相同的结果。 - talya.gendler
1个回答

3

根据评论编辑:

方法 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
请注意,我只提供了Linux的逻辑,对于Windows可以使用类似的逻辑,但需要使用批处理脚本语法。
方法2:
假设域已经安装,并且用户提供了需要添加JVM参数“-Dmy.property”的服务器列表。使用Jython脚本(使用wlst.sh执行)。 WLST参考
用法: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

为了在JVM参数中获得特定于主机的"USERPROFILE"值,必须从将要部署托管服务器的所有主机运行脚本。

顺便说一下,回答你的问题:看起来JVM参数最终必须提供文字文本。但是,如果将环境变量作为JVM参数提供,则似乎WLS不会将其翻译。当从startWebLogic.cmd(例如使用%DOMAIN_HOME%等)启动时,它会给人以翻译的印象,但实际上是shell/cmd执行程序先进行翻译,然后再启动JVM。


我该如何使用startWebLogic.cmd来确定哪个托管服务器将接收此值?我不希望为域中的所有托管服务器设置此值,只想为其中特定的一组托管服务器设置。 - talya.gendler
更具体地说,我需要一种方法来为域中的任何子集(可能是分布式的)设置此JAVA_OPTION。子集由用户输入确定,我事先不知道。 - talya.gendler
Mani,谢谢你的帮助 :)一个想法-如果我们找到了如何转义引号的方法(我尝试了许多解决方案并花费了大量的Google时间,但没有成功),那么使用wlst不是更容易吗?您认为这是否会导致评估在运行时发生? - talya.gendler
1
好的。听到这个很棒。我想我没有清楚地解释脚本循环。希望你明白它是如何工作的。基本上是这样的:startManagedWebLogic.sh -> startWebLogic.sh -> setDomainEnv.sh。使用"export或set"的任何变量值都将被传递。 - Mani
不太清楚为什么从startManagedWebLogic.sh开始它没有起作用。 我会重试的,但是现在我知道它可以做到了,我想找到正确的脚本现在是容易的部分。 再次感谢! - talya.gendler
显示剩余13条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接