Tomcat server.xml解析器

时间:2011-08-31 20:01:46

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

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

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:1)

您可以使用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.

答案 2 :(得分:0)

以编程方式执行此操作是否是一种好习惯?