【问题标题】:Tomcat server.xml parserTomcat server.xml 解析器
【发布时间】:2011-08-31 20:01:46
【问题描述】:

我需要修改代码,Tomcat的server.xml
好的,它只是一个 XML 文件,有很多方法可以解析它,但我想知道是否已经有专门用于 server.xml 的 API(例如来自 Apache),并且不必编写任何代码来解析它。
有吗?
注意:解析server.xml 的程序将“离线”执行,即它不是Valve 或其他有权访问容器的组件的一部分

【问题讨论】:

    标签: java xml jakarta-ee tomcat xml-parsing


    【解决方案1】:

    通过xml生成xsd(使用IDEA或something)->通过xsd生成jaxb表示(使用jaxb)不会花费很长时间

    【讨论】:

    • 我想这样做,但是 jaxb 生气了(当然是我的错,但我无法理解如何)并返回我的可序列化列表而不是我的适当 bean,这阻止了我
    【解决方案2】:

    您可以使用 Tomcat 用于加载 server.xml 的相同解析例程,即 Commons Digester。这样您就可以重用常规的 Tomcat catalina.jar 并避免生成的代码过时。

    来自startup sequence 文档:

            b3) createStartDigester() 
                Configures a digester for the main server.xml elements like
                org.apache.catalina.core.StandardServer (can change of course :)
                org.apache.catalina.deploy.NamingResources
                    Stores naming resources in the J2EE JNDI tree
                org.apache.catalina.LifecycleListener
                    implements events for start/stop of major components
                org.apache.catalina.core.StandardService
                    The single entry for a set of connectors,
                    so that a container can listen to multiple connectors
                    ie, single entry
                org.apache.coyote.tomcat5.CoyoteConnector
                    Connectors to listen for incoming requests only
                It also adds the following rulesets to the digester
                    NamingRuleSet
                    EngineRuleSet
                    HostRuleSet
                    ContextRuleSet
            b4) Load the server.xml and parse it using the digester
                Parsing the server.xml using the digester is an automatic
                XML-object mapping tool, that will create the objects defined in server.xml
                Startup of the actual container has not started yet.
    

    【讨论】:

      【解决方案3】:

      以编程方式执行它甚至是一种好习惯吗?

      【讨论】:

      • 如果您正在制作安装程序,则非常有用
      猜你喜欢
      • 1970-01-01
      • 2011-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-18
      • 2013-01-14
      • 2018-01-20
      • 1970-01-01
      相关资源
      最近更新 更多