How to have built-in tomcat with manager web application

The idea is to have a self-contained project (well, at least for development), without having to configure an external tomcat, but the problem with using tomcat7-maven-plugin is, correct me, if I am wrong, the built-in version of tomcat does not contain an application "manager", and I just don't want to start the whole server every time.

So the question is, what is the best way to incorporate the webapp manager into the built-in tomcat?

+3
source share
2 answers

I got Managerworking by doing @olamy in my solution. Since it was still some work to run it, and my solution is somewhat different from him, and since information about this is rarely found on the Internet, I am going to show how I did it in detail.

Firstly, this is the project structure of my WAR:

Image of WAR structure

I downloaded the manager.war file from the @olamy link and placed it inside WEB-INFunder tomcat/manager. I left the WAR file there for convenience, but you can simply delete it after extracting its contents, as shown in the screenshot above. You can really place the folder anywhere, just make sure you update the document’s basic attribute for it server.xml.

Inside pom.xmlI configured tomcat7-maven-pluginas follows:

<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
    <port>9090</port>
    <path>/webapp</path>
    <serverXml>./src/main/tomcat/conf/server.xml</serverXml>
    <contextFile>./src/main/tomcat/conf/context.xml</contextFile>
    <tomcatUsers>./src/main/tomcat/conf/tomcat-users.xml</tomcatUsers>
    <tomcatLoggingFile>./src/main/tomcat/conf/logging.properties</tomcatLoggingFile>
    <additionalConfigFilesDir>./src/main/tomcat/conf</additionalConfigFilesDir>
</configuration>

, additionalConfigFilesDir , , , , , . logging.properties context.xml , server.xml tomcat-users.xml Manager.

, :

server.xml

<?xml version="1.0" encoding="UTF-8"?>
<Server port="9090" shutdown="SHUTDOWN">
    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
    <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>

    <GlobalNamingResources>
        <!-- Used by Manager -->
        <Resource name="UserDatabase" auth="Container"
                  type="org.apache.catalina.UserDatabase"
                  description="User database that can be updated and saved"
                  factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
                  pathname="conf/tomcat-users.xml" readonly="true"/>
    </GlobalNamingResources>

    <Service name="Catalina">
        <Connector port="9090" keepAliveTimeout="1800000" maxKeepAliveRequests="30000" maxThreads="300"/>
        <Engine name="Catalina" defaultHost="localhost">
            <Valve className="org.apache.catalina.valves.AccessLogValve" resolveHosts="false" buffered="false"
                   pattern="%t-ip:%a-protocol::%H-status:%s-localPort:%p-path:%U-time:%D ms"/>
            <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
            <Host name="localhost" appBase="webapps" autoDeploy="true" unpackWARs="true" deployXML="false">
                <Context path="/manager" docBase="../../<your WAR root folder name>/WEB-INF/tomcat/manager" privileged="true"/>
            </Host>
        </Engine>
    </Service>
</Server>

users.xml-

<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users>
    <role rolename="manager"/>
    <role rolename="manager-gui"/>
    <role rolename="manager-script"/>
    <user username="admin" password="password" roles="manager, manager-gui, manager-script"/>
</tomcat-users>

Tomcat 7 mvn tomcat7:run-war Manager URL http://localhost:9090/manager admin/password.

+5

All Articles