maven

来源:互联网 发布:淘宝店铺怎么利用营销 编辑:程序博客网 时间:2024/06/10 10:45
pom.xml


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <!--所有的Maven项目都必须配置这四个配置项-->
    <modelVersion>4.0.0</modelVersion>
    <!--groupId指的是项目名的项目组,默认就是包名-->
    <groupId>cn.gacl.maven.hello</groupId>
    <!--artifactId指的是项目中的某一个模块,默认命名方式是"项目名-模块名"-->
    <artifactId>hello-first</artifactId>
    <!--version指的是版本,这里使用的是Maven的快照版本-->
    <version>SNAPSHOT-0.0.1</version>
</project>


快速新建一个maven项目
mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false


1.进入到项目根目录,然后使用命令”mvn compile”进行编译,
使用Maven编译完成之后,在项目根目录下会生成一个target文件夹


2.使用"mvn clean"命令清除编译结果,也就是把编译生成的target文件夹删掉


3. mvn test
3.1 mvn test-compile


4. mvn package


5. mvn install


6. mvn process-resources
you can execute the following command (process-resources is the build lifecycle phase where the resources are copied and filtered):


setting up, building, testing, packaging, and installing a typical Maven project


7. mvn clean compile -Duser.name=foobar 在编译时加入系统变量
8. 
在编译项目时,可以使用 -P 参数指定需要使用的 profile 的 id,比如下面命令将会使用 development profile:
$mvn clean compile -Pdevelopment


9. maven scope

对于scope=compile的情况(默认scope),也就是说这个项目在编译,测试,运行阶段都需要这个artifact对应的jar包在classpath中。

而对于scope=provided的情况,则可以认为这个provided是目标容器已经provide这个artifact。换句话说,它只影响到编译,测试阶段。在编译测试阶段,我们需要这个artifact对应的jar包在classpath中,而在运行阶段,假定目标的容器(比如我们这里的liferay容器)已经提供了这个jar包,所以无需我们这个artifact对应的jar包了

当我们用maven install生成最终的构件包ProjectABC.war后,在其下的WEB-INF/lib中,会包含我们被标注为scope=compile的构件的jar包,而不会包含我们被标注为scope=provided的构件的jar包。这也避免了此类构件当部署到目标容器后产生包依赖冲突。



<project>


  ...


  <profiles>


    <profile>


      <id>development</id>


      <activation>


        <activeByDefault>true</activeByDefault>


      </activation>


      <build>


        <filters>


          <filter>profile-development.properties</filter>


        </filters>


      </build>


    </profile>


    <profile>


      <id>production</id>


      <build>


        <filters>


          <filter>profile-production.properties</filter>


        </filters>


      </build>


    </profile>


  </profiles>


</project>
假如不指定 -P 参数的话,则会使用 activeByDefault=true 的一项(即 development)

0 0
原创粉丝点击