Maven learning

Maven Profile

By using profiles, different compilation and packaging behaviors can be made according to different environments and targets, as shown in the following pom files

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

Execution mvn package -P devis packaged according to the test environment, and execution mvn package -P testis packaged according to the test environment

Running java classes through Maven

For a maven project, it is very difficult to run a certain java class directly through the java command in the console, because it is difficult to solve the dependency problem. At this time, using the maven command can solve the problem of dependencies very well.

method 1

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

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

Method 3

Method 3 is to use profile to nest method 2, in order to meet different needs

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325438290&siteId=291194637