zoukankan      html  css  js  c++  java
  • Java:使用Maven对普通java程序打包(可运行包 与 可引用包)

    依开发环境需要,有时我们并不会运行到框架打包,这时就需要依靠Maven进行普通java程序的打包。

    打包可运行jar包(不包括依赖的其他jar包)

    pom.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>org.example</groupId>
        <artifactId>Test</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.0.0</version>
    <configuration> <archive> <manifest> <!--这里改成你的main方法类路径--> <mainClass>com.dll.test.PlanMethod</mainClass> </manifest> </archive> </configuration> </plugin> </plugins> </build> </project>

    打包可运行jar包(包括依赖的其他jar包)

    pom.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>org.example</groupId>
        <artifactId>Test</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.0.0</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <!--这里改成你的main方法类路径-->
                                <mainClass>com.dll.test.PlanMethod</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id> <!-- 这里用于继承合并 -->
                            <phase>package</phase> <!-- 绑定到打包阶段 -->
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>

    打包可依赖jar包和可运行jar包(包括依赖的其他jar包

    pom.xml文件

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>org.example</groupId>
        <artifactId>Test</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <build>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.0.0</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <!--这里改成你的main方法类路径-->
                                <mainClass>com.dll.test.PlanMethod</mainClass>
                            </manifest>
                        </archive>
                        <!-- 配置生成的可运行jar名称 -->
                        <descriptorRefs>
                            <descriptorRef>exec</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id> <!-- 这里用于继承合并 -->
                            <phase>package</phase> <!-- 绑定到打包阶段 -->
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                        <!-- 在执行package动作的时候,自动打包 -->
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
    </project>

    Java程序打包

    如果大家是IDEA、Eclipse的话可运行clear、install打包,如果不是的可用命令打包

    #运行maven命令打包程序(在pom.xml目录下运行)
    mvn package

    文章转载至:https://blog.csdn.net/strongyoung88/article/details/54097830

    ----------------------------------- 作者:怒吼的萝卜 链接:http://www.cnblogs.com/nhdlb/ -----------------------------------
  • 相关阅读:
    ping 介绍
    密码学系列——简介密码学
    ActiveMQ c# 系列——进阶实例(三)
    转:LVS简介
    口罩与mask------看东西方文化差异
    Java设计模式之单利模式(Single Pattern)
    Cadence OrCAD Cpature创建Title Block
    终极干货,数组去重且显示每一个数据重复的次数
    LeetCode 64. 最小路径和 | Python
    LeetCode 剑指 Offer 11. 旋转数组的最小数字 | Python
  • 原文地址:https://www.cnblogs.com/nhdlb/p/15567691.html
Copyright © 2011-2022 走看看