将 java 系统属性设置为 java 应用程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1326818/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 08:18:36  来源:igfitidea点击:

Setting java system properties to a java application

javatomcatproperties

提问by Ben

Possible Duplicate:
How can I specify system properties in Tomcat configuration on startup?

可能重复:
如何在启动时在 Tomcat 配置中指定系统属性?

What i'm trying to do, eventually, is to start TOMCAT with certain java system properties set (in this case jmx setup):

我最终想要做的是使用某些 java 系统属性集(在本例中为 jmx 设置)启动 TOMCAT:

-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9898 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false`

)

)

Problem is I don't think i'm doing it right. What I'm doing is, in the command prompt window (Working in Vista 64, BTW) I use:

问题是我认为我做得不对。我正在做的是,在命令提示符窗口(在 Vista 64 中工作,顺便说一句)中,我使用:

set CATALINA_OPTS=-Dcom.sun.management.jmxremote...
set JAVA_OPTS=-Dcom.sun.management.jmxremote...
tomcat6.exe

This doesn't seem to work since tomcat6 is not behaving as if the properties were set. To test this I used the example Notepad.Jar that comes with the java jdk. Tried to run it the same way:

这似乎不起作用,因为 tomcat6 的行为不像设置了属性。为了测试这一点,我使用了 java jdk 附带的示例 Notepad.Jar。尝试以相同的方式运行它:

set JAVA_OPTS=-Dcom.sun.management.jmxremote...
java -jar Notepad.jar

which didn't work, but this did work:

这没有用,但这确实有效:

java -Dcom.sun.management.jmxremote .... -jar Notepad.jar

Since the last attempt did work I concluded that the JAVA/CATALINA_OPTS setup is incorrect.

由于上次尝试成功,我得出结论 JAVA/CATALINA_OPTS 设置不正确。

Could someone point out what i'm doing wrong? I hope I was clear enough.

有人能指出我做错了什么吗?我希望我说得够清楚了。

Thanks!

谢谢!

采纳答案by Pablojim

Use the supplied startup.bat and catalina.bat files instead of calling tonmcat.exe directly. This has always worked for me...

使用提供的 startup.bat 和 catalina.bat 文件,而不是直接调用 tonmcat.exe。这一直对我有用...

回答by Andreas Dolk

AFAIK, these variables are used by the tomcat startup script and not by Java directly. Here's a link that might help you:

AFAIK,这些变量由 tomcat 启动脚本使用,而不是由 Java 直接使用。这是一个可能对您有所帮助的链接:

CATALINA_OPTS v JAVA_OPTS - What is the difference?

CATALINA_OPTS v JAVA_OPTS - 有什么区别?

回答by Ben

I managed to do this by running the server from bootstrap.jar in a similiar manner to the way I started notepad.jar.

我设法通过以与启动 notepad.jar 的方式类似的方式从 bootstrap.jar 运行服务器来做到这一点。

java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9898 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -jar bootstrap.jar

Apparently catalina.bat and startup.bat do no exists in tomcat6.0. I haven't found proper documentation for the changes from 5.5 to 6.0 which describe the removal of these startup batch files, which is a shame because i'm still not sure i'm doing it the correct way. Although it works which is, I guess, a good start.

显然 catalina.bat 和 startup.bat 在 tomcat6.0 中不存在。我还没有找到有关从 5.5 到 6.0 的更改的正确文档,其中描述了这些启动批处理文件的删除,这很遗憾,因为我仍然不确定我是否以正确的方式执行此操作。虽然它有效,但我想这是一个好的开始。

回答by n002213f

try;

尝试;

set JAVA_OPTS=-Dcom.sun.management.jmxremote...
java %JAVA_OPTS% -jar Notepad.jar

take note of %JAVA_OPTS%

注意%JAVA_OPTS%