烂笔头一、
在POM 4中,<dependency>中还引入了scope,它主要管理依赖的部署。目前<scope>可以使用5个值:
* compile,缺省值,适用于所有阶段,会随着项目一起发布。* provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。
* runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。
* test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。
* system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。
例如:
<span style="white-space:pre"> </span><dependency>
<span style="white-space:pre"> </span><groupId>javax.servlet</groupId>
<span style="white-space:pre"> </span> <span style="white-space:pre"> </span><artifactId>servlet-api</artifactId>
<span style="white-space:pre"> </span><version>2.5</version>
<span style="white-space:pre"> </span><scope>provided</scope>
</dependency>
烂笔头二、maven打包插件
<span style="white-space:pre"> </span> <!--打包插件,把web打成zip包-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
<executions>
<!-- 当执行mvn package时才会打包 -->
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
另外还需要assembly.xml
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>dwr01</id>
<formats>
<!-- zip,tar,tar.gz,tar.bz2,jar,dir,war -->
<format>zip</format>
</formats>
<dependencySets>
<!-- 依赖包的输出路径 -->
<dependencySet>
<outputDirectory>/lib</outputDirectory>
</dependencySet>
</dependencySets>
<!-- 需要打包的文件集 -->
<fileSets>
<fileSet>
<outputDirectory>/</outputDirectory>
<directory>/</directory>
<includes>
<include>/**</include>
</includes>
<excludes>
<exclude>/target/**</exclude>
</excludes>
</fileSet>
</fileSets>
</assembly>
烂笔头三、maven导出项目所有jar包
mvn dependency:copy-dependencies -DoutputDirectory=lib(导出的目录) -DincludeScope=compile(编译级别)
从Maven项目中导出项目依赖的jar包:进入工程pom.xml 所在的目录下,执行如下命令:
mvn dependency:copy-dependencies
或者在eclipse中执行:dependency:copy-dependencies
烂笔头四、使用jetty插件
<span style="white-space:pre"> </span> <plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.16.v20140903</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<webApp>
<contextPath>/dwr01</contextPath>
</webApp>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8888</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
</configuration>
</plugin>
烂笔头五、使用tomcat插件
tomcat的插件有很多种,这是其中的一种,使用的是apache的maven插件
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<path>/abc</path>
<port>8080</port>
<uriEncoding>UTF-8</uriEncoding>
<url>http://localhost:8080/manager/html</url>
</configuration>
</plugin>