5

如何将具有空格的属性传递JAVA_OPTS给 Apache Tomcat?

例如;

-Dmy.property="How are you"

我的操作系统是 SUSE Linux。

4

4 回答 4

1

实际上,我使用 AWS Elasticbeanstalk 解决了这个问题,它允许您在环境属性中留出空间,您可以通过 UI 输入。

作为服务器实例构建的一部分,Elasticbeanstalk 服务替换了 /usr/bin/tomcat7 脚本以适应它的一些要求。

如果你检查这个,你可以看到以下区别:

默认脚本:

if [ "$1" = "start" ]; then
    ${JAVACMD} $JAVA_OPTS $CATALINA_OPTS \

Elasticbeanstalk 脚本:

if [ "$1" = "start" ]; then
    eval "${JAVACMD} $JAVA_OPTS $CATALINA_OPTS \
    ...."

即,他们在启动 JVM 的命令之前放置了一个“eval”,并将整个命令用双引号括起来。

这似乎允许保留带有空格的 JAVA_OPTS 值。

于 2017-04-14T12:52:58.633 回答
0

在我看来,没有办法在 JAVA_OPTS 中使用空格,我在 OSX 上也有同样的问题。您可以将您的属性直接添加到 catalina.sh 中的其他 -D 选项

于 2013-12-05T11:52:09.243 回答
0

让我们打开文件$CATALINA_HOME\bin\catalina.sh。您将看到来自 Apache Tomcat 的变量指南JAVA_OPTS

#   JAVA_OPTS       (Optional) Java runtime options used when any command
#                   is executed.
#                   Include here and not in CATALINA_OPTS all options, that
#                   should be used by Tomcat and also by the stop process,
#                   the version command etc.
#                   Most options should go into CATALINA_OPTS.

您想要设置属性-Dmy.property="How are you",它不是 JVM 支持的属性。你应该把它放在变量中CATALINA_OPTS。如果您的属性值有空格,请将其包裹在" ".

#   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
#                   "run" or "debug" command is executed.
#                   Include here and not in JAVA_OPTS all options, that should
#                   only be used by Tomcat itself, not by the stop process,
#                   the version command etc.
#                   Examples are heap size, GC logging, JMX ports etc.

(虽然您使用的是 Apache Tomcat 5.5,但我引用了 Apache Tomcat 9.0.11 的指南,因为它存在于我的计算机中)

于 2018-08-31T23:14:17.733 回答
-3

尝试这个

-Dmy.property="How\ are\ you"
于 2010-12-22T20:35:00.390 回答