【问题标题】:Set title for Java window when running tomcat运行tomcat时设置Java窗口的标题
【发布时间】:2012-08-14 12:16:41
【问题描述】:

我正在编写一个脚本来启动几个 tomcat 服务器,就像这样

cd "F:\...\apache-tomcat-5.5.33\bin"
call "cmd /c startup.bat"
cd "F:\...\apache-tomcat-5.5.33\bin"
call "cmd /c startup.bat"
etc

我正在工作,但每个都在一个 java 窗口中打开,顶部只显示“tomcat”。我可以具体说明这段文字的内容吗?我真的很想能够把它们区分开来!

【问题讨论】:

    标签: java cmd


    【解决方案1】:

    您必须设置一个环境变量。阅读最后一篇写着TITLE 的文章。我在catalina.bat 中找到了这个。

    rem ---------------------------------------------------------------------------
    rem Start/Stop Script for the CATALINA Server
    rem
    rem Environment Variable Prerequisites
    rem
    rem   Do not set the variables in this script. Instead put them into a script
    rem   setenv.bat in CATALINA_BASE/bin to keep your customizations separate.
    rem
    rem   CATALINA_HOME   May point at your Catalina "build" directory.
    rem
    rem   CATALINA_BASE   (Optional) Base directory for resolving dynamic portions
    rem                   of a Catalina installation.  If not present, resolves to
    rem                   the same directory that CATALINA_HOME points to.
    rem
    rem   CATALINA_OPTS   (Optional) Java runtime options used when the "start",
    rem                   "run" or "debug" command is executed.
    rem                   Include here and not in JAVA_OPTS all options, that should
    rem                   only be used by Tomcat itself, not by the stop process,
    rem                   the version command etc.
    rem                   Examples are heap size, GC logging, JMX ports etc.
    rem
    rem   CATALINA_TMPDIR (Optional) Directory path location of temporary directory
    rem                   the JVM should use (java.io.tmpdir).  Defaults to
    rem                   %CATALINA_BASE%\temp.
    rem
    rem   JAVA_HOME       Must point at your Java Development Kit installation.
    rem                   Required to run the with the "debug" argument.
    rem
    rem   JRE_HOME        Must point at your Java Runtime installation.
    rem                   Defaults to JAVA_HOME if empty. If JRE_HOME and JAVA_HOME
    rem                   are both set, JRE_HOME is used.
    rem
    rem   JAVA_OPTS       (Optional) Java runtime options used when any command
    rem                   is executed.
    rem                   Include here and not in CATALINA_OPTS all options, that
    rem                   should be used by Tomcat and also by the stop process,
    rem                   the version command etc.
    rem                   Most options should go into CATALINA_OPTS.
    rem
    rem   JAVA_ENDORSED_DIRS (Optional) Lists of of semi-colon separated directories
    rem                   containing some jars in order to allow replacement of APIs
    rem                   created outside of the JCP (i.e. DOM and SAX from W3C).
    rem                   It can also be used to update the XML parser implementation.
    rem                   Defaults to $CATALINA_HOME/endorsed.
    rem
    rem   JPDA_TRANSPORT  (Optional) JPDA transport used when the "jpda start"
    rem                   command is executed. The default is "dt_socket".
    rem
    rem   JPDA_ADDRESS    (Optional) Java runtime options used when the "jpda start"
    rem                   command is executed. The default is 8000.
    rem
    rem   JPDA_SUSPEND    (Optional) Java runtime options used when the "jpda start"
    rem                   command is executed. Specifies whether JVM should suspend
    rem                   execution immediately after startup. Default is "n".
    rem
    rem   JPDA_OPTS       (Optional) Java runtime options used when the "jpda start"
    rem                   command is executed. If used, JPDA_TRANSPORT, JPDA_ADDRESS,
    rem                   and JPDA_SUSPEND are ignored. Thus, all required jpda
    rem                   options MUST be specified. The default is:
    rem
    rem                   -agentlib:jdwp=transport=%JPDA_TRANSPORT%,
    rem                       address=%JPDA_ADDRESS%,server=y,suspend=%JPDA_SUSPEND%
    rem
    rem   LOGGING_CONFIG  (Optional) Override Tomcat's logging config file
    rem                   Example (all one line)
    rem                   set LOGGING_CONFIG="-Djava.util.logging.config.file=%CATALINA_BASE%\conf\logging.properties"
    rem
    rem   LOGGING_MANAGER (Optional) Override Tomcat's logging manager
    rem                   Example (all one line)
    rem                   set LOGGING_MANAGER="-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
    rem
    rem   TITLE           (Optional) Specify the title of Tomcat window. The default
    rem                   TITLE is Tomcat if it's not specified.
    rem                   Example (all one line)
    rem                   set TITLE=Tomcat.Cluster#1.Server#1 [%DATE% %TIME%]
    rem
    rem
    rem
    rem $Id: catalina.bat 1344732 2012-05-31 14:08:02Z kkolinko $
    rem ---------------------------------------------------------------------------
    

    【讨论】:

    • 我的 catalina.bat 比这稍微不友好,但我确实找到了一些关于设置标题并修改它以适应我的需要,谢谢。
    • @adarshr:完美的答案。自定义标题看起来很酷。
    【解决方案2】:

    catalina.bat 中进行以下更改:

    :doStart
    ...
    if "%TITLE%" == "" set TITLE=MY TOMCAT TITLE
    

    其中 MY TOMCAT TITLE 是您要赋予 Java 窗口的标题。

    【讨论】:

    • 谢谢,这(几乎)正是我所需要的。我使用一个变体来显示当前目录(我在我的机器上运行了许多 Tomcat),所以我将 TITLE 设置为 %CD%
    • 很好,我喜欢基于当前目录的自动标题的想法
    • 如何更改控制台tomcat的颜色?
    猜你喜欢
    • 2013-04-12
    • 2021-09-20
    • 1970-01-01
    • 2019-12-05
    • 2011-04-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多