tomcat7-maven-plugin custom server.xml

好久不见. 提交于 2020-01-10 05:40:28

问题


I am trying to use the tomcat7-maven-plugin:run with a custom server.xml, which contains a Realm I need to enable. As described in the docs I have used <serverXml /> to point to my file. However, my application does not then get loaded. The plugin docs state that I need to configure the context for my application manually.

How do I do this? I am unsure what to put for the docBase etc.

Thanks.


回答1:


Can you check this sample pom http://svn.apache.org/repos/asf/tomcat/maven-plugin/trunk/tomcat7-maven-plugin/src/test/resources/deploy-war-project/pom.xml




回答2:


If all you need is change the Realm then instead of using server.xml use context.xml with your realm:

<Context>
  <Realm className="org.apache.catalina.realm.MemoryRealm" />
</Context>

Point your tomcat maven plugin to that context.xml:

<plugin>
  <groupId>org.apache.tomcat.maven</groupId>
  <artifactId>tomcat6-maven-plugin</artifactId>
  <version>2.0</version>
  ...
  <configuration>
    ...
    <contextFile>tomcat/context.xml</contextFile>
    ...
  </configuration>
</plugin>



回答3:


I have configured custom server.xml with the reference taken from downloaded tomcat distribution and have updated port number and others, when I had issues followed below answer. embedded tomcat custom server.xml configuration issues Note:It is working only in tomcat7-maven-plugin artifact with version 2.1 but not 2.2

Find my pom.xml and server.xml

  <project>
  ...
  <packaging>war or pom</packaging>
  ...
  <build>
    ...
    <plugins>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <warName>secured-sample-webapp</warName>
                    <webResources>
                        <resource>
                            <directory>src/main/webapp</directory>
                            <filtering>true</filtering>
                            <includes>
                                <include>**/*.tag</include>
                                <include>**/*.jsp</include>
                            </includes>
                        </resource>
                        <resource>
                            <directory>src/main/webapp</directory>
                            <filtering>false</filtering>
                            <excludes>
                                <exclude>**/*.tag</exclude>
                                <exclude>**/*.jsp</exclude>
                            </excludes>
                        </resource>
                    </webResources>
                    <packagingExcludes>less/**</packagingExcludes>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>install</id>
                        <phase>install</phase>
                        <goals>
                            <goal>sources</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

            <plugin>
                    <groupId>org.apache.tomcat.maven</groupId>
                    <artifactId>tomcat7-maven-plugin</artifactId>
                    <version>2.1</version>
                    <executions>
                      <execution>
                        <id>tomcat-run</id> 
                        <goals>
                          <goal>exec-war-only</goal>
                        </goals>
                        <phase>package</phase>
                        <configuration>
                          <path>/secured-sample-webapp</path>
                          <warDirectory>target/secured-sample-webapp</warDirectory>
                          <!-- optional, needed only if you want to use a preconfigured server.xml file -->
                          <serverXml>src/main/tomcatconf/server.xml</serverXml>
                          <!-- optional values which can be configurable -->
                          <attachArtifactClassifier>exec-war</attachArtifactClassifier>
                          <attachArtifactClassifierType>jar</attachArtifactClassifierType>
                          <finalName>secured-sample-webapp-exec.jar</finalName>
                          <enableNaming>true</enableNaming>
                        </configuration>
                      </execution>
                    </executions>
               </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

and Server.xml

 <Server port="8005" shutdown="SHUTDOWN">
  <!--  <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> -->
  <!-- Security listener. Documentation at /docs/config/listeners.html
  <Listener className="org.apache.catalina.security.SecurityListener" />
  -->
  ...
  <Service>
  ...
  <Engine>
  ...
  <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

             <Context docBase="../../secured-sample-webapp" path="/secured-sample-webapp" reloadable="true" />

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>

    </Engine>
  </Service>
</Server>


来源:https://stackoverflow.com/questions/13604377/tomcat7-maven-plugin-custom-server-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!