WebLogic - 在“参数"中使用环境变量/双引号;在“服务器启动"中 [英] WebLogic - Using environment variable / double quotes in "Arguments" in "Server Start"

查看:37
本文介绍了WebLogic - 在“参数"中使用环境变量/双引号;在“服务器启动"中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台管理服务器、NodeManager 和 1 台托管服务器,它们都在同一台机器上.我正在尝试在服务器启动"选项卡中的参数字段中输入类似于此的内容:

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:

打开 zip 文件或 JAR 清单时出错:%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 '"'"

即使手动编辑 config.xml 文件也无法工作,因为在此之后管理服务器无法启动:

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 '"'.>

我也尝试使用 %20 无济于事,它只是作为 %20 传递.

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

我认为这可能与 %USERPROFILE% 值中的空格有关(即C:\documents and settings.."),但同样的事情发生在其他环境指向没有空格的其他目录的变量.

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.

我的问题:

是否有任何支持的方式:

  1. 使用双引号?如果我必须引用名称中包含空格的文件夹怎么办?

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

引用环境变量?如果我必须依赖它的值来处理我事先不知道变量值的分布式服务器怎么办?

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:

  1. 打开 setDomainEnv.cmd 并在 Linux 中搜索 export SERVER_NAME 或在 Windows 中搜索 set SERVER_NAME.跳到下一行(即跳过当前和下一行)
  2. 在当前行插入:

  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

  • 保存 setDomainEnv.sh 文件并重启服务器
  • 请注意,我只给出了 Linux 的逻辑,对于 Windows 可以使用类似的逻辑,但使用批处理脚本语法.

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

    方法 2:

    假设域已经安装并且用户提供了需要添加 JVM 参数 -Dmy.property 的服务器列表.Jython 脚本(使用 wlst.sh 执行).WLST 参考.

    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.

    用法: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"值.

    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.

    顺便说一句,要在一行中回答您的问题:看起来 JVM 参数最终必须与文字文本一起提供.但看起来 WLS 如果作为 JVM 参数提供,则不会转换环境变量.它给人的印象是它在从 startWebLogic.cmd 完成时正在翻译(例如:使用 %DOMAIN_HOME% 等),但它的 shell/cmd 执行器会翻译然后启动 JVM.

    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.

    这篇关于WebLogic - 在“参数"中使用环境变量/双引号;在“服务器启动"中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆