Maven学习

Maven Profile

通过使用profile可以根据不同的环境和目标做出不同的编译打包行为,如下pom文件

<profiles>  
    <profile>  
        <id>dev</id>  
        xxxx
    </profile>  
    <profile>  
        <id>test</id>  
        xxxx
    </profile>  
</profiles>  

执行mvn package -P dev则按照测试环境打包, 执行mvn package -P test则按照测试环境打包

通过Maven运行java类

一个maven工程,在控制台下想通过java命令直接运行某一个java类是非常困难的,因为很难解决依赖问题。这时使用maven命令能够很好的解决依赖的问题。

方法1

mvn exec:java -Dexec.mainClass="xxx"

方法2

<build>  
 <plugins>  
  <plugin>  
   <groupId>org.codehaus.mojo</groupId>  
   <artifactId>exec-maven-plugin</artifactId>  
   <version>1.1.1</version>  
   <executions>  
    <execution>  
     <phase>test</phase>  
     <goals>  
      <goal>java</goal>  
     </goals>  
     <configuration>  
      <mainClass>mainclass</mainClass>  
      <arguments>  
       <argument>arg0</argument>  
       <argument>arg1</argument>  
      </arguments>  
     </configuration>  
    </execution>  
   </executions>  
  </plugin>  
 </plugins>  
</build>  

方法3

方法3是利用profile对方法2的嵌套,目的为满足不同的需求

<profiles>  
 <profile>  
  <id>code-generator</id>  
  <build>  
   按照方法2补充这里的配置
  </build>  
 </profile>  
</profiles>

猜你喜欢

转载自my.oschina.net/u/2328171/blog/1601665
今日推荐