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/ -----------------------------------
  • 相关阅读:
    One special dictionary
    What is mobile platform?
    Linux 学习 二, 安装JDK
    Design Pattern ->Abstract Factory
    Entity Framework 使用注意:Where查询条件中用到的关联实体不需要Include
    在使用ICSharpCode.SharpZipLib进行目录压缩后,再解压缩是提示这个错误Size mismatch: 4294967295;126976 70202;126976
    在C#中利用SharpZipLib进行文件的压缩和解压缩收藏
    JavaScript中的匿名函数及函数的闭包
    让ConfigurationManager打开任意的配置文件
    C# 读取与修改配置文件
  • 原文地址:https://www.cnblogs.com/nhdlb/p/15567691.html
Copyright © 2011-2022 走看看