Maven 多模块项目在eclipse下面热部署(Tomcat7、Jetty)

时间:2021-02-22 13:35:30

   多模块项目的结构,“erpt-test” 是主项目,“erpt-parent”是所有子模块的parent。

Maven 多模块项目在eclipse下面热部署(Tomcat7、Jetty)

  1. Tomcat7 配置: 在“erpt-test”的POM里配置
     1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     2   <modelVersion>4.0.0</modelVersion>
     3   <groupId>com.sgm.erpt</groupId>
     4   <artifactId>erpt-test</artifactId>
     5   <version>0.0.1-SNAPSHOT</version>
     6   <packaging>pom</packaging>
     7   <modules>
     8       <module>erpt-parent</module>
     9       <module>erpt-parent-service</module>
    10       <module>erpt-data</module>
    11       <module>erpt-parent-dao</module>
    12       <module>erpt-project1-dao</module>
    13       <module>erpt-project1-service</module>
    14       <module>erpt-parent-web</module>
    15       <module>erpt-parent-entity</module>
    16       <module>erpt-project1-entity</module>
    17       <module>erpt-analyze</module>
    18       <module>erpt-project1-web</module>
    19       <module>erpt-web</module>
    20   </modules>
    21       
    22     <build>
    23         <plugins>
    24             <plugin>
    25                 <groupId>org.apache.tomcat.maven</groupId>
    26                 <artifactId>tomcat7-maven-plugin</artifactId>
    27                 <version>2.0-beta-1</version>
    28                 <configuration>
    29                     <port>9080</port>
    30                     <path>/</path>
    31                     <contextFile>D:/workspace_maven_test/erpt-test/erpt-web/src/main/resources/tomcatconf/context.xml</contextFile>
    32                     <contextReloadable>true</contextReloadable>
    33                     <useTestClasspath>false</useTestClasspath>
    34                 </configuration>
    35                 <dependencies>
    36                     <dependency>
    37                       <groupId>com.oracle</groupId>
    38                       <artifactId>ojdbc14</artifactId>
    39                       <version>xe</version>
    40                     </dependency>
    41                 </dependencies>
    42             </plugin>
    43         </plugins>
    44     </build>
    45 </project>

    其中contextFile主要配置的是JNDI数据源的

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <!--
     3   Licensed to the Apache Software Foundation (ASF) under one or more
     4   contributor license agreements.  See the NOTICE file distributed with
     5   this work for additional information regarding copyright ownership.
     6   The ASF licenses this file to You under the Apache License, Version 2.0
     7   (the "License"); you may not use this file except in compliance with
     8   the License.  You may obtain a copy of the License at
     9 
    10       http://www.apache.org/licenses/LICENSE-2.0
    11 
    12   Unless required by applicable law or agreed to in writing, software
    13   distributed under the License is distributed on an "AS IS" BASIS,
    14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   See the License for the specific language governing permissions and
    16   limitations under the License.
    17 --><!-- The contents of this file will be loaded for each web application -->
    18 
    19 <Context reloadable="false">
    20 
    21     <!-- Default set of monitored resources -->
    22     <WatchedResource>WEB-INF/web.xml</WatchedResource>
    23     
    24     <!-- Uncomment this to disable session persistence across Tomcat restarts -->
    25     <!--
    26     <Manager pathname="" />
    27     -->
    28 
    29     <!-- Uncomment this to enable Comet connection tacking (provides events
    30          on session expiration as well as webapp lifecycle) -->
    31     <!--
    32     <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
    33     -->
    34 
    35 <Resource
    36 name="jdbc/UM"
    37 type="javax.sql.DataSource"
    38 username="OWAVT"
    39 password="password"
    40 driverClassName="oracle.jdbc.driver.OracleDriver"
    41 url="jdbc:oracle:thin:@127.0.0.1:1521:XE" />
    42 
    43 </Context>

    配置插件后会在项目的War项目的Target生成一个tomcat的文件夹,里面有个tomcat-users.xml文件

     1 <?xml version='1.0' encoding='utf-8'?>
     2 <!--
     3   Licensed to the Apache Software Foundation (ASF) under one or more
     4   contributor license agreements.  See the NOTICE file distributed with
     5   this work for additional information regarding copyright ownership.
     6   The ASF licenses this file to You under the Apache License, Version 2.0
     7   (the "License"); you may not use this file except in compliance with
     8   the License.  You may obtain a copy of the License at
     9 
    10       http://www.apache.org/licenses/LICENSE-2.0
    11 
    12   Unless required by applicable law or agreed to in writing, software
    13   distributed under the License is distributed on an "AS IS" BASIS,
    14   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   See the License for the specific language governing permissions and
    16   limitations under the License.
    17 -->
    18 <tomcat-users>
    19 
    20   <role rolename="tomcat"/>
    21   <role rolename="UMRole"/>
    22   <user username="tomcat" password="tomcat" roles="tomcat"/>
    23   <user username="both" password="tomcat" roles="tomcat,role1"/>
    24   <user username="test01" password="password" roles="UMRole"/>
    25 
    26 </tomcat-users>

    最后在M2E里配置

    Maven 多模块项目在eclipse下面热部署(Tomcat7、Jetty)

  2. run-jetty-run插件, run-jetty-run是一个用jetty运行/调试Web项目的Eclipse插件,通过M2E插件结合Maven使用简直就是Web项目调试神器。如果用tomcat什么的,想要在Eclipse里面直接调试使用Maven管理的多模块项目简直是一件折磨死人的事情,用RJR什么都不用配置,直接项目右键-->DEBUG AS-->Run jetty就行了,
    run-jetty-run update site: http://run-jetty-run.googlecode.com/svn/trunk/updatesite