列出 Apache Tomcat 中已部署的 Web 应用程序

发布于 2024-12-11 02:50:57 字数 207 浏览 0 评论 0 原文

我需要获取 Apache Tomcat 中已部署的 Web 应用程序的列表。另外,对于每个 Web 应用程序,我需要获取已初始化的 Servlet 和 JSP 的列表。有什么想法可以做到这一点吗?

我发现目录 \tomcat\work\Catalina\localhost\ 包含每个 Web 应用程序的子目录。是否还有其他已部署的 Web 应用程序不存在?

I need to get a list of deployed webapps in Apache Tomcat. Also, for each webapp I need to get a list of initialized servlets and JSPs. Any ideas how this can be done?

I've found that the directory \tomcat\work\Catalina\localhost\ contains a child directory for each webapp. Could there be any other deployed webapps that aren't present there?

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

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

发布评论

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

评论(7

菊凝晚露 2024-12-18 02:50:57

为了获取 Tomcat 已部署应用程序的列表,您只需配置用户/角色并使用 /manager/text/list tomcat 端点

在 Tomcat 中配置用户和角色

将其添加到您的 / .../.../TOMCAT_HOME/conf/tomcat-users.xml

<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>

<user username="my_user" password="my_pass" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>

您可以跳过“admin-gui”和“admin-gui”。如果您不执行管理操作,则为“admin-script”角色。

之后,重新启动 tomcat

使用浏览器列出应用程序

转到您最喜欢的浏览器并输入此网址:

http://some_ip:some_port/manager/text/list

将出现登录信息。输入在 TOMCAT_HOME/conf/tomcat-users.xml 中配置的用户/密码

命令

使用命令行只需执行以下

curl -v -u my_user:my_pass http://127.0.0.1:some_port/manager/text/list

:结果应该是:

OK - Listed applications for virtual host localhost
/manager:running:0:manager
/:running:0:ROOT
/docs:running:0:docs
/examples:running:0:examples
/host-manager:running:0:host-manager
/my_app:running:0:my_app
/my_other_app:running:0:my_other_app
....
* Connection #0 to host 127.0.0.1 left intact

列出与自动化 tomcat 部署相关的插件使用的带有 curl 的应用程序(DevOps)

HTH

In order to get a list of deployed apps of your tomcat you just need configure user/roles and use /manager/text/list tomcat endpoint

Configure user and roles in Tomcat

Add this in your /.../.../TOMCAT_HOME/conf/tomcat-users.xml

<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<role rolename="admin-gui"/>
<role rolename="admin-script"/>

<user username="my_user" password="my_pass" roles="manager-gui,manager-script,manager-jmx,manager-status,admin-gui,admin-script"/>

You could skip "admin-gui" & "admin-script" roles if you will not perform admin operations.

After that, restart tomcat

List apps using browser

Go to your favorite browser and enter this url:

http://some_ip:some_port/manager/text/list

A login will appear. Enter the user/password configured in your TOMCAT_HOME/conf/tomcat-users.xml

Using command line

Just execute this:

curl -v -u my_user:my_pass http://127.0.0.1:some_port/manager/text/list

The result should be:

OK - Listed applications for virtual host localhost
/manager:running:0:manager
/:running:0:ROOT
/docs:running:0:docs
/examples:running:0:examples
/host-manager:running:0:host-manager
/my_app:running:0:my_app
/my_other_app:running:0:my_other_app
....
* Connection #0 to host 127.0.0.1 left intact

List apps with curl is used by a plugins related to automated tomcat deploys (Devops)

HTH

晚风撩人 2024-12-18 02:50:57

您可以使用 javax.management 来完成此操作。它看起来像

private Iterable<String> collectAllDeployedApps() {
    try {
        final Set<String> result = new HashSet<>();
        final Set<ObjectName> instances = findServer()
                .queryNames(new ObjectName("Tomcat:j2eeType=WebModule,*"), null);
        for (ObjectName each : instances) {
            result.add(substringAfterLast(each.getKeyProperty("name"), "/")); //it will be in format like //localhost/appname 
        }
        return result;
    } catch (MalformedObjectNameException e) {
         //handle
    }
}

private MBeanServer findServer() {
    ArrayList<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
    for (MBeanServer eachServer : servers) {
        for (String domain : eachServer.getDomains()) {
            if (domain.equals("Tomcat")) {
                return eachServer;
            }
        }
    }
    //handle. We are not in Tomcat.
}

You can do it by using javax.management. It will look like

private Iterable<String> collectAllDeployedApps() {
    try {
        final Set<String> result = new HashSet<>();
        final Set<ObjectName> instances = findServer()
                .queryNames(new ObjectName("Tomcat:j2eeType=WebModule,*"), null);
        for (ObjectName each : instances) {
            result.add(substringAfterLast(each.getKeyProperty("name"), "/")); //it will be in format like //localhost/appname 
        }
        return result;
    } catch (MalformedObjectNameException e) {
         //handle
    }
}

private MBeanServer findServer() {
    ArrayList<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
    for (MBeanServer eachServer : servers) {
        for (String domain : eachServer.getDomains()) {
            if (domain.equals("Tomcat")) {
                return eachServer;
            }
        }
    }
    //handle. We are not in Tomcat.
}
葮薆情 2024-12-18 02:50:57

手动引用:List_Currently_Deployed_Applications

http://localhost:8080/manager/text/list

Manual quote: List_Currently_Deployed_Applications

http://localhost:8080/manager/text/list
苹果你个爱泡泡 2024-12-18 02:50:57

我不知道该怎么做。但是tomcat的标准发行版中有一个管理器应用程序,它列出了已部署的应用程序。提供了源码,大家可以看一下。

关于您关于其他 webapp 的问题:是的,可能还有其他 webapp,它们不在 webapp 目录中。它们可以在 server.xml 中指定。

I don't know how to do it. But there is a manager application in the standard distribution of tomcat, which lists the deployed apps. Sourcecode is provided, so you could have a look there.

Regarding your question about other webapps: Yes, there could be other webapps, which resides not in the webapp directory. They could be specified in the server.xml.

悲凉≈ 2024-12-18 02:50:57

我发现有关已部署应用程序及其内容(包括 servlet、文件、连接等)的信息的最佳方法是安装 Lambda 探测

The best way I found for information about the deployed applications and their content (including servlets, files, connections and such) is to install Lambda Probe in addition to whatever the tomcat instance is serving.

不羁少年 2024-12-18 02:50:57

查看 Apache Tomcat 手册。第 5 节介绍 Tomcat 中的 Manager 应用程序,它就是这样做的。

Check out the Apache Tomcat manual. Section 5 is about the Manager application in Tomcat, which does just that.

风吹雪碎 2024-12-18 02:50:57

http://code.google.com/p/psi-probe/wiki/Features 似乎是一个值得一看的好地方。

http://code.google.com/p/psi-probe/wiki/Features seems like a good place to look.

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