bash 使用空格使用 JAVA_OPTIONS 进行 JVM 调优?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3866965/
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
JVM Tuning with JAVA_OPTIONS using a space?
提问by Fran Fitzpatrick
Okay, so I'm adding an argument to my JAVA_OPTIONS as documented here. However, it is not working because of the space. Here is the line I am using in the UNIX shell script (just as the documentation specifies):
好的,所以我正在向我的 JAVA_OPTIONS 添加一个参数,如此处所述。但是,由于空间原因,它不起作用。这是我在 UNIX shell 脚本中使用的行(正如文档指定的那样):
JAVA_OPTIONS="-DFRAMEWORK_HOME=${app_home}/conf
-Dcom.sun.xml.namespace.QName.useCompatibleSerialVersionUID=1.0
\"-Dcom.sun.jndi.ldap.connect.pool.protocol=plain ssl\""
But I am getting the following error:
但我收到以下错误:
Exception in thread "main" java.lang.NoClassDefFoundError:
"-Dcom/sun/jndi/ldap/connect/pool/protocol=plain
I can easily do it if I do protocol=plain ORprotocol=ssl, but I really need it to be "plain ssl".
如果我做protocol=plain ORprotocol=ssl,我可以很容易地做到,但我真的需要它是“plain ssl”。
Can anyone help?
任何人都可以帮忙吗?
回答by David J. Liszewski
Double quotes enclosing command line options where escaped double quotes surround the property value having a space seems to work.
包含命令行选项的双引号,其中转义双引号围绕具有空格的属性值似乎有效。
$ export JAVA_OPTIONS="-Dcom.sun.xml.namespace.QName.useCompatibleSerialVersionUID=1.0 \
-Dcom.sun.jndi.ldap.connect.pool.protocol=\"plain ssl\""
$ cat P.java
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.List;
public class P {
public static void main(String[] args) {
Enumeration<?> e = System.getProperties().propertyNames();
List<String> list = new ArrayList<String>();
while (e.hasMoreElements()) {
list.add((String) e.nextElement());
}
Collections.sort(list);
for (String key : list) {
System.out.println(key + "=" + System.getProperty(key));
}
}
}
$ javac -d ~/classes P.java
$ java -classpath ~/classes $JAVA_OPTIONS P | grep com.sun.jndi.ldap.connect.pool.protocol
com.sun.jndi.ldap.connect.pool.protocol=plain ssl
回答by SOA Nerd
First off.....I'm kinda thinking that whoever decided that the option should include a blank space should be court-martialed by the Java police :-).
首先.....我有点想,无论谁决定该选项应该包含一个空格,都应该由 Java 警察进行军事法庭审判:-)。
That being said...as you said your problem is the space. The way to get rid of this is to enclose it in quotation marks. I haven't tried this, but can you try changing it to:
话虽如此……正如您所说,您的问题是空间。摆脱这种情况的方法是将其括在引号中。我没有试过这个,但你能不能尝试把它改成:
JAVA_OPTIONS='-DFRAMEWORK_HOME=${app_home}/conf
-Dcom.sun.xml.namespace.QName.useCompatibleSerialVersionUID=1.0
-Dcom.sun.jndi.ldap.connect.pool.protocol=\"plain ssl\"'

