Maven常用记录

烂笔头一、

在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>


?
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员阿宁

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值