bash 通过 JAVA_OPTS 将包含空格的系统属性传递给 Tomcat
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18358660/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Passing system properties that contains spaces to Tomcat through JAVA_OPTS
提问by AlexBrand
I need to pass multiple system properties to Tomcat 6 through the JAVA_OPTS environment variable. I can't seem to pass system properties that contain spaces:
我需要通过 JAVA_OPTS 环境变量将多个系统属性传递给 Tomcat 6。我似乎无法传递包含空格的系统属性:
JRE_HOME=/root/jre1.6.0_34/ JAVA_OPTS="-DsysProp1=foo -DsysProp2=bar with spaces" ./catalina.sh run
Fails with:
失败:
Using CATALINA_BASE: /root/apache-tomcat-6.0.37
Using CATALINA_HOME: /root/apache-tomcat-6.0.37
Using CATALINA_TMPDIR: /root/apache-tomcat-6.0.37/temp
Using JRE_HOME: /root/jre1.6.0_34/
Using CLASSPATH: /root/apache-tomcat-6.0.37/bin/bootstrap.jar
Exception in thread "main" java.lang.NoClassDefFoundError: with
Caused by: java.lang.ClassNotFoundException: with
at java.net.URLClassLoader.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: with. Program will exit.
I looked around on SO and the answers don't seem to help. Tried all of these with no success:
我环顾四周,答案似乎没有帮助。尝试了所有这些都没有成功:
JRE_HOME=/root/jre1.6.0_34/ JAVA_OPTS="-DsysProp1=foo -DsysProp2=\"bar with spaces\"" ./catalina.sh run
JRE_HOME=/root/jre1.6.0_34/ JAVA_OPTS='-DsysProp1=foo -DsysProp2="bar with spaces"' ./catalina.sh run
JRE_HOME=/root/jre1.6.0_34/ JAVA_OPTS='-DsysProp1=foo -DsysProp2=bar\ with\ spaces' ./catalina.sh run
采纳答案by Ian Roberts
As an alternative you could put the property settings into conf/catalina.properties
instead of using JAVA_OPTS
. This is a standard java.util.Properties
format file so you don't need to quote anything, it simply takes everything before the first equals sign, colon or space as the property name and everything after that as the value:
作为替代方案,您可以将属性设置放入conf/catalina.properties
而不是使用JAVA_OPTS
. 这是一个标准java.util.Properties
格式文件,因此您不需要引用任何内容,它只需将第一个等号、冒号或空格之前的所有内容作为属性名称,并将其后的所有内容作为值:
sysProp2=bar with spaces
If you can't (or would prefer not to) modify that file directly, you can copy it to another location, edit the copy, and then pass
如果您不能(或不想)直接修改该文件,您可以将其复制到另一个位置,编辑副本,然后通过
-Dcatalina.config=file:/path/to/copy/of/catalina.properties
in JAVA_OPTS
to make it load your properties from there.
在JAVA_OPTS
使它从那里加载性能。
回答by Aleks-Daniel Jakimenko-A.
Alright. Thanks for providing the link to the actual script.
Here is what catalina.sh
does:
好吧。感谢您提供指向实际脚本的链接。这是catalina.sh
它的作用:
exec "$_RUNJAVA" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS # ... more stuff
So it is going to be split by spaces no matter what you do. There is no way to fix that without changing catalina.sh
file.
所以无论你做什么,它都会被空格分割。如果不更改catalina.sh
文件,则无法解决此问题 。
This page answer the question in detail: http://mywiki.wooledge.org/BashFAQ/050
本页详细回答问题:http: //mywiki.wooledge.org/BashFAQ/050