zoukankan      html  css  js  c++  java
  • 3、maven笔记(三):项目打包

    1.通过执行mvn clean package,可以对项目进行打包,源代码生成为jar包形式,在target目录下产生以"artifact-version.jar"格式命名的jar包,本次产生的jar为:hello-world-1.0-SNAPSHOT.jar
    2.而通过观察在target目录下产生:hello-world-1.0-SNAPSHOT.jar;,即编译的成功的jar包,但是不能运行,因为虽然里面有main方法,但是通过解压,打开MANIFEST.MF文件,里面没有Main-Class项,如果要jar可以运行,则:
    在pom.xml添加plugin,在projectuildplugins节点下:
    <build>
            <plugins>
                <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.zmp.mvn.helloworld.HelloWorld</mainClass>
                                    </transformer>
                                </transformers>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

    3.因为如果想让其他maven项目之间引用该jar包,须执行mvn clean install命令,可以安装到本地maven库;
    4.之后之间运行jar包就可以了,如下图:
    5.maven主要命令(maven clean compile, mvn clean test, mvn clean package, mvn clean install)执行顺序:
    • 执行test之前先执行compile;
    • 执行package之前先执行test;
    • 类似的执行install之前先执行package;





  • 相关阅读:
    Java学习01-使用maven插件tomcat搭建web maven项目
    Anaconda3安装及使用
    python标准日志模块logging及日志系统设计
    python traceback捕获并打印异常
    python time
    PIL 中的 Image 模块
    python zipfile使用
    PHP 判断用户是否手机访问
    php数组相加 两个数组键名相同 后者不能覆盖前者
    解决Ubuntu Server 12.04换了网卡MAC地址后 网络不可用的问题.
  • 原文地址:https://www.cnblogs.com/zmpandzmp/p/9689228d0de845d97a28b7f957f38f12.html
Copyright © 2011-2022 走看看