我有一个像这样的属性文件(user.properties):
vc.ip=10.161.22.102,10.161.19.112
adminUserName=admin
adminPassword=password
sshUserName=userName
sshPassword=password
所以我把它包括在内:
<property file="user.properties"/>
之后我可以将vc.ip
称为$ {vc.ip}。
但之后我想分割vc.ip
并将值(10.161.22.102和10.161.19.112)存储在不同的变量中。我怎样才能做到这一点?
我试过这个:
<script language="javascript">
project.setProperty('variable1', project.getProperty(${vc.ip}).split(',')[0]);
project.setProperty('variable2', project.getProperty(${vc.ip).split(',')[1]);
</script>
但是我收到以下错误:
project.setProperty('vcIp', project.getProperty(${vc.ip).split(',')[0]);
^ in <eval> at line number 2 at column number 57
at jdk.nashorn.api.scripting.NashornScriptEngine.throwAsScriptException(NashornScriptEngine.java:586)
at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:653)
at jdk.nashorn.api.scripting.NashornScriptEngine.compileImpl(NashornScriptEngine.java:640)
at jdk.nashorn.api.scripting.NashornScriptEngine.evalImpl(NashornScriptEngine.java:521)
at jdk.nashorn.api.scripting.NashornScriptEngine.eval(NashornScriptEngine.java:192)
at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:264)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.tools.ant.util.ReflectUtil.invoke(ReflectUtil.java:108)
at org.apache.tools.ant.util.ReflectWrapper.invoke(ReflectWrapper.java:81)
at org.apache.tools.ant.util.optional.JavaxScriptRunner.evaluateScript(JavaxScriptRunner.java:103)
at org.apache.tools.ant.util.optional.JavaxScriptRunner.executeScript(JavaxScriptRunner.java:67)
at org.apache.tools.ant.taskdefs.optional.Script.execute(Script.java:52)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:435)
at org.apache.tools.ant.helper.ProjectHelper2.parse(ProjectHelper2.java:180)
at org.apache.tools.ant.ProjectHelper.configureProject(ProjectHelper.java:93)
at org.apache.tools.ant.Main.runBuild(Main.java:826)
at org.apache.tools.ant.Main.startAnt(Main.java:235)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
Caused by: jdk.nashorn.internal.runtime.ParserException: <eval>:2:57 Expected , but found {
project.setProperty('vcIp', project.getProperty(${vc.ip}).split(',')[0]);
我试过这种方式:
<script language="javascript">
project.setProperty('variable1', project.getProperty('vc.ip').split(',')[0]);
project.setProperty('variable2', project.getProperty('vc.ip').split(',')[1]);
</script>
但是我收到以下错误:
javax.script.ScriptException: TypeError: null has no such function "split" in <eval> at line number 2