Eclipse + Maven + Tomcat Web项目本地部署
本地老项目直接添加到Tomcat无法运行。
查看部署目录发现配置文件冲突了。
老项目采用了maven的多环境配置,可能有点问题。
实际情况说起来有点复杂,但需要搞清楚的知识点只有几个:
- Java Build Path中配置output 文件位置
- Maven profile + resources 配置根据maven命令参数 copy配置文件 从 源码到编译结果目录
- Deployment Assembly 配置哪些文件需要从编译结果目录copy到tomcat部署目录
我们要的结果就是在Tomcat目录中得到正确的编译文件。
容易错误的点
- 第一点和第二点 都是从源码到编译结果
一个是Eclipse自带的编译 一个是Maven的编译有可能文件会冲突
target/classes是他们的默认编译结果文件目录。 - m2e-wtp
实测来看这里放的是根据maven profile配置copy过来的项目配置。
比如下面的配置,得到的是dev文件夹里面的配置,不包括common/properties。
<profile>
<id>dev</id>
<properties>
<final.name>xxx</final.name>
<package.environment>dev</package.environment>
<tomcat.port>8080</tomcat.port>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
...
<resources>
<resource>
<directory>src/main/resources/common/properties</directory>
</resource>
<resource>
<directory>src/main/resources/common/spring_conf</directory>
</resource>
</resources>
附录
http://wiki.eclipse.org/M2E-WTP
m2e-wtp aims at providing a tight integration between Maven Integration for Eclipse (a.k.a m2e) and the Eclipse Web Tools Project (WTP).
m2e-wtp provides a set of m2e connectors used for the configuration of Java EE projects in WTP. It features :
Support for war projects : adds the Java and Dynamic Web Facets. Support war overlays and on-the-fly resource filtering
Support for ejb projects : adds the Java and EJB Facets. Supports deployment descriptor filtering.
Support for ear projects : adds the EAR Facet. Supports application.xml and jboss.xml file generation, resource filtering
Support for rar projects : adds the Java and Connector Facets.
Support for app-client projects : adds the Java and Application Client Facets. Supports deployment descriptor filtering.
Support for jar dependency projects : adds the Java and Utility Facets.
Support for web-fragment projects : adds the Java and Web Fragment Facets if a web-fragment.xml file is detected in the resource folders.
This project is originally known as m2eclipse-wtp, which has been developed on GitHub and has been moved to Eclipse, as a subproject of m2e.