Maven使用--打包和运行

 
  将项目进行编译、测试后,下一个重要步骤就是打包。简单执行命令mvn clean package进行打包。Maven会在打包前执行编译、测试等操作。
 
  在打包后,执行安装任务install。从输出可以看到该任务将项目输出的jar安装到了Maven本地仓库中,可以打开相应的文件夹看到HelloWorld项目的pom和jar。
 
 要运行Hello World项目,默认打包生产的jar是不能够直接运行的,因为带有main方法的类信息不回添加到manifest中。为了生成可执行的jar文件,需要借助maven-shade-plugin。配置如下:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-shade-plugin</artifactId>
     <version>1.2.1</version>
     <executions>
          <execution>
               <phase>package</phase>
               <goals>
                    <goal>shade</goal>
               </goals>
               <configuration>
                    <transformers>
                    <transformer implementation = "org.apache.maven.plugins.shade.resource.
                    ManifestResourceTransformer">
                    <mainClass> com.action.mvnbook.helloworld.HelloWorld</mainClass>
                    </transformer>
                    </transformers>
               </configuration>
          </execution>
         </executions>
     </plugin>

  

 
  plugin元素在POM中的相对位置应该在<project> <build> <plugins>下面。项目打包时会将该信息放到MANIFEST中。
 
使用Archetype生成项目骨架
 
  Maven提供Archetype帮助我们快速勾勒出项目骨架。
  mvn archetype:generate
原文地址:https://www.cnblogs.com/mywy/p/5070336.html