Eclipse + Maven + Tomcat Web项目本地部署

本文介绍了使用Eclipse、Maven和Tomcat进行Web项目部署过程中遇到的问题及解决方法,重点讲解了如何处理多环境配置冲突,确保正确配置被复制到目标目录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值