tomcat7-maven-plugin自定义server.xml

时间:2012-11-28 11:48:44

标签: tomcat maven maven-3

我正在尝试使用tomcat7-maven-plugin:运行自定义server.xml,其中包含我需要启用的Realm。如文档中所述,我使用<serverXml />指向我的文件。但是,我的应用程序不会被加载。插件文档声明我需要手动为我的应用程序配置上下文。

我该怎么做?我不确定要为docBase等添加什么。

感谢。

3 个答案:

答案 0 :(得分:2)

答案 1 :(得分:0)

如果你需要的只是改变领域,那么而不是使用server.xml使用你的领域context.xml

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

将tomcat maven插件指向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>

答案 2 :(得分:0)

当遇到以下问题时,我已经配置了自定义的server.xml,其中的引用来自下载的tomcat发行版,并更新了端口号和其他端口。 embedded tomcat custom server.xml configuration issues 注意:它仅在版本2.1而不是2.2的tomcat7-maven-plugin工件中工作

找到我的pom.xml和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>

和  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>