Maven POM 配置技巧(一)

一、排除传递依赖的某个jar,以避免版本冲突。例如: 开发工程中需要引用struts2(2.0.11.2)和freemarker(2.3.16),但该struts2默认依赖的是freemarker(2.3.8),可参考以下方式编写:

view plain
<dependency>
<groupId>org.apache.struts</groupId>
<artifactId>struts2-core</artifactId>
<version>2.0.11.2</version>
<type>jar</type>
<scope>compile</scope>
<exclusions>
<exclusion> <!-- 排除freemarker,以避免版本冲突 -->
<groupId>freemarker</groupId>
<artifactId>freemarker</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.16</version>
<type>jar</type>
<scope>compile</scope>
</dependency>




二、发布jar包同时发布源码

view plain
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.1.2</version>
<configuration>
<attach>true</attach>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>




三、Eclipse开发时,为方便使用内置tomcat调试,需将所依赖的jar包复制到WEB-INF/lib目录下。可通过以下配置:

view plain
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>src/main/webapp/WEB-INF/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

配置完成后。每次有添加jar包依赖时,需运行一次mvn package命令。





四、有时工程中想复用其它工程中的静态内容(image/css/js),为方便开发调试,需将相应的静态内容,解压缩到当前工程的webapp目录下。可通过以下配置:
view plain
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>copy-statics</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.yihaodian.front</groupId>
<artifactId>front-global</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>statics</classifier>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>src/main/webapp</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>


配置完成后,需运行一次mvn generate-resources命令。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值