Maven常用记录

阅读(14)
评论(0)
Beginning

烂笔头一、

在POM 4中,<dependency>中还引入了scope,它主要管理依赖的部署。目前<scope>可以使用5个值: 

* compile,缺省值,适用于所有阶段,会随着项目一起发布。 
* provided,类似compile,期望JDK、容器或使用者会提供这个依赖。如servlet.jar。 
* runtime,只在运行时使用,如JDBC驱动,适用运行和测试阶段。 
* test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。 
        * system,类似provided,需要显式提供包含依赖的jar,Maven不会在Repository中查找它。 

例如:

1
2
3
4
5
6
<dependency>   
       <groupId>javax.servlet</groupId>   
       <artifactId>servlet-api</artifactId>   
       <version>2.5</version>   
        <scope>provided</scope>   
</dependency>

  

烂笔头二、maven打包插件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<!--打包插件,把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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?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插件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<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插件

1
2
3
4
5
6
7
8
9
10
11
<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>

  




 

 

?
Ending
本文如果对您有帮助欢迎打赏作者,多少随意一分也是爱!

作者:Java夜未眠

出处:https://www.cnblogs.com/liangxianning/p/17058272.html

版权声明:本博客所有文章除特别声明外,均采用「 MIT 许可协议。」许可协议进行许可

关于博主: 评论和私信会可能回复较慢,点击上面加人图标加我为好友吧

posted @   Java夜未眠  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
more_horiz
keyboard_arrow_up light_mode
选择主题
点击右上角即可分享
微信分享提示