我有一个管理服务器、NodeManager 和 1 个托管服务器,它们都位于同一台计算机上。 我正在尝试在“服务器启动”选项卡中的参数字段中输入与此类似的内容:
-Dmy.property=%USERPROFILE%\someDir\someJar.jar
但是当托管服务器启动时,它会抛出此异常:
Error opening zip file or JAR manifest missing : %USERPROFILE%\someDir\someJar.jar
环境变量似乎没有被转换成它的值。它只是以纯文本形式传递到托管服务器。 我尝试用双引号 (") 将路径引起来,但控制台验证输入并不允许这样做:"参数可能不包含 '"'"
即使手动编辑 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:
- 打开 setDomainEnv.cmd 并在 Linux 中搜索
export SERVER_NAME
或在 Windows 中搜索set SERVER_NAME
。跳到下一行(即跳过当前行和下一行) 在当前行插入:
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 可以使用类似的逻辑,但使用批处理脚本语法。
方法 2:
假设域已安装,并且用户提供了需要添加 JVM 参数 -Dmy.property
的服务器列表。 Jython 脚本(使用 wlst.sh 执行)。 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”的主机特定值。
顺便说一句,在一行中回答你的问题:看起来 JVM 参数最终必须与文字文本一起提供。但看起来 WLS 不会转换作为 JVM 参数提供的环境变量。它给人的印象是,当它从 startWebLogic.cmd 完成时(例如:使用 %DOMAIN_HOME% 等),它正在进行翻译,但它是由 shell/cmd 执行器进行翻译,然后启动 JVM。
关于WebLogic - 在 "Arguments"中的 "Server Start"中使用环境变量/双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12629395/