maven 之 插件收集 之二(java mainClass, exec)

1. 执行一个.exe 程序或java Main-class 

<plugin>
	        <groupId>org.codehaus.mojo</groupId>
	        <artifactId>exec-maven-plugin</artifactId>
	        <version>1.2.1</version>
	        <executions>
	          <execution> 
	            <goals>
	              <goal>exec</goal>
	            </goals>
	          </execution>
	        </executions>
	        <configuration>
	          <executable>Startup.exe</executable>
	       <!--    optional
	          <workingDirectory>/tmp</workingDirectory>
	          <arguments>
	            <argument>-X</argument>
	            <argument>myproject:dist</argument>
	            ...
	          </arguments>
	           --> 
	        </configuration>
	      </plugin>

  <plugin>
	        <groupId>org.codehaus.mojo</groupId>
	        <artifactId>exec-maven-plugin</artifactId>
	        <version>1.2.1</version>
	        <executions>
	          <execution> 
	            <goals>
	              <goal>java</goal>
	            </goals>
	          </execution>
	        </executions>
	        <configuration> 
	           <mainClass>example.hmp.generator.EdiGenerator</mainClass>
	        </configuration>
	      </plugin>

这两个主要是指定的goal 不一样,一个是exec 而一个是java

可以用该命令可以看到对应的goal 的参数

 mvn exec:help -Ddetail=true -Dgoal=<goal-name>

 

2. 打包时进行引入或排除目录和文件

<plugin>
    <artifactId>maven-jar-plugin</artifactId>
    <executions>
        <execution>
            <id>default-jar</id>
            <configuration>
                <excludes>
                    <exclude>**/somepackage/*</exclude>
                </excludes>
            </configuration>
        </execution>
        <execution>
            <id>special-jar</id>
            <phase>package</phase>
            <goals>
                <goal>jar</goal>
            </goals>
            <configuration>
                <includes>
                    <include>**/sompackage/*</include>
                </includes>
                <classifier>somepackage</classifier>
            </configuration>
        </execution>
    </executions>
</plugin>


3. 在打包时,复制相关依赖jar 到构建目录

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>true</overWriteSnapshots>
                            <excludeTransitive>false</excludeTransitive>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

你可能感兴趣的:(maven 之 插件收集 之二(java mainClass, exec))