在使用Java中使用嵌入式服务器时,如何将Tomcat版本隐藏在错误消息中

发布于 2025-02-10 23:03:38 字数 433 浏览 2 评论 0原文

我有一个Java应用程序,我正在使用嵌入式的tomcat服务器, 看起来这样,

Tomcat tomcat = new Tomcat()

我在这里创建了嵌入式的tomcat服务器。

问题语句

每当有错误时,它会显示我正在使用的tomcat版本的信息,

如何将其隐藏在Java中?

我有一个想法,我需要覆盖 serverinfo.properties ,但是我该怎么做?

I have a java application where i'm using embedded Tomcat servers,
which looks like this

Tomcat tomcat = new Tomcat()

I'm creating an embedded tomcat server here.

Problem statement

whenever there's an error it displays information on which tomcat version i'm using,
enter image description here

how to hide this in java?

i have a little idea that i need to override ServerInfo.properties, but how do i do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

佼人 2025-02-17 23:03:38

我不确定如何在Java中执行此操作,但是如果您使用任何构建脚本(例如Ant / gradle)来进行分配目的,我们可以编写一个任务来覆盖 /硬化JAR文件,并替换 serverInfo。属性文件,具有自定义值的内容。

ANT构建脚本的代码看起来像

<target name="override.tomcat">
        <jar destfile="path/to/tomcat-embed-core-9.0.62.jar" update="true">
            <fileset dir="src/"> <!-- folder where you keep the directory/file to raplace-->
                <include name="org/apache/catalina/util/ServerInfo.properties"/> <!-- file to replace within directory path in side the jar-->
            </fileset>
        </jar>
    </target>

,在Gradle中,

task overRideTomcat(type: Jar) {
    from(zipTree(file("path/to/tomcat-embed-core-9.0.62.jar"))) {
        exclude '**/org/apache/catalina/util/ServerInfo.properties'
    }

    from('src/') {
        include('/org/apache/catalina/util/ServerInfo.properties')
    }

    archiveName "tomcat-embed-core-9.0.62.jar"
}

请确保您在SRC目录下使用了与您在Include语句中提到的相同路径中的修改后的properties文件。

I'm not sure how we can do this in java, but if you are using any build scripts like ant / gradle for distribution purpose, we can write a task to override / harden the jar file, and replace the ServerInfo.properties file with the customized value whatever we need.

the code for ant build scripts would look like

<target name="override.tomcat">
        <jar destfile="path/to/tomcat-embed-core-9.0.62.jar" update="true">
            <fileset dir="src/"> <!-- folder where you keep the directory/file to raplace-->
                <include name="org/apache/catalina/util/ServerInfo.properties"/> <!-- file to replace within directory path in side the jar-->
            </fileset>
        </jar>
    </target>

and in gradle

task overRideTomcat(type: Jar) {
    from(zipTree(file("path/to/tomcat-embed-core-9.0.62.jar"))) {
        exclude '**/org/apache/catalina/util/ServerInfo.properties'
    }

    from('src/') {
        include('/org/apache/catalina/util/ServerInfo.properties')
    }

    archiveName "tomcat-embed-core-9.0.62.jar"
}

make sure you have the modified ServerInfo.properties file under src directory in the same path as you have mentioned in the include statement.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文