运行Tomcat并使用自己的server.xml部署项目 [英] Run Tomcat and deploy project with own server.xml

查看:88
本文介绍了运行Tomcat并使用自己的server.xml部署项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想运行一个使用pom.xml在maven项目中配置的Web项目。
它使用maven tomcat7-maven-plugin来部署Web应用程序工件,此时所有工作正常。

I just want to run a web project that has been configured in a maven project with the pom.xml. It uses the maven tomcat7-maven-plugin to deploy the web app artifact and all is working properly at this point.

现在我想添加自己的tomcat配置中的server.xml和tomcat-users.xml。我读到我需要添加以下行。

Now I want to add its own server.xml and tomcat-users.xml in the tomcat configuration. I read that I need to add the following lines.

 <serverXml>src/main/resources/tomcat/server.xml</serverXml>
 <tomcatUsers>src/main/resources/tomcat/tomcat-users.xml</tomcatUsers>

这没关系。它现在正在运行,并且使用上面的配置文件部署了tomcat,但问题是> 没有在那里部署Web应用程序工件(当我运行tomcat7:run时不会自动部署)。似乎插件没有检测到工件,只是启动tomcat服务器而不将工件添加到webapps只需使用新的配置文件。

And that is fine. It is working now and tomcat is deployed using the configuration file above,but the problem is > Web application artifact is not deployed there (is not deployed automatically when I run tomcat7:run). It seems the artifact is not detected by the plugin and just starts the tomcat server without adding the artifact to the webapps just use the new config files.

我使用此配置。

<plugin>
    <groupId>org.apache.tomcat.maven</groupId>
    <artifactId>tomcat7-maven-plugin</artifactId>
    <version>2.0</version>
    <executions>
          <execution>
            <id>tomcat-run</id>
            <goals>
              <goal>exec-war-only</goal>
            </goals>
            <phase>package</phase>
           <configuration>
        <url>http://localhost:8080/web-services</url>
        <path>/web-services</path>
        <serverXml>src/main/resources/tomcat/server.xml</serverXml>
                <tomcatUsers>src/main/resources/tomcat/tomcat-users.xml</tomcatUsers>
                   <warRunDependencies>
                    <warRunDependency>
                     <dependency>
                        <groupId>com.koitoer.webservices</groupId>
                        <artifactId>web-services</artifactId>
                        <version>1.0-SNAPSHOT</version>
                        <type>war</type>
                      </dependency>
                    <contextPath>/web-services</contextPath>
                </warRunDependency>
              </warRunDependencies>
    </configuration>
    </execution>
        </executions>
</plugin>

但是tomcat开始部署webapp工件,但不使用新的配置文件。

But tomcat starts deploy the webapp artifact but does not use the new config files.

那里的配置是什么,我检查了这个发布但没有,这是可能的,或者我应该使用tomcat管理器手动添加war文件?

What is the correct configuration there, I checked this post but nothing, this is possible or I should add the war file manually using tomcat manager?

推荐答案

< a href =http://tomcat.apache.org/maven-plugin-2.0/tomcat7-maven-plugin/run-mojo.html#serverXml =noreferrer> tomcat7-maven-plugin文档说< serverXml>


server.xml使用请注意,如果您使用此功能,则必须在此文件中配置
您的webapp路径。

我认为这意味着您必须在< Host> 元素中插入< Context> 元素以及您的战争路径,像这样:

I think this means that you have to insert a <Context> element with the path of your war inside the <Host> element, like so:

<Host appBase="webapps" autoDeploy="true" deployXML="false" name="localhost" unpackWARs="true">
    <Context docBase="../../webapp" path="/webapp" reloadable="true" />
</Host>

webapp是我生成的战争名称。显然, appBase 是相对于 target / tomcat (并且webapps似乎是默认值)。 docBase 相对于 appBase 所以为了简单起见,我使用了构建目录的相对路径。

Where "webapp" is my generated war name. Apparently, appBase is relative to target/tomcat (and "webapps" seems to be the default value). docBase is relative to appBase so for simplicity I used the relative path to the build directory.

这对我有用,没有那个< Context> 元素我得到一个白页。

This is working for me, and without that <Context> element I get a white page.

如果您使用过滤,您可以用属性替换 docBase 。但是请注意从war文件中排除server.xml(和tomcat-users.xml)!

If you are using filtering you can probably replace docBase by a property. However take care to exclude the server.xml (and tomcat-users.xml) from your war file!

这篇关于运行Tomcat并使用自己的server.xml部署项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆