Maven will rely on third-party packages to package (package) into the jar

Prerequisite : The project is a pure maven java project, created through file-->new-->project-->maven in the idea, not a spring boot project (not through file-->new-->project--> , The spring boot project can pass the default ), no additional operations are required.

1. Encountered a problem, the project is packaged, and there is no third-party package in the jar

Directory Structure

 

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>com</groupId>
    <artifactId>EnctyptParamTool</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <fastjson.version>1.2.32</fastjson.version>
    </properties>
    <dependencies><!--本地添加模式-->
        <!--
        <dependency>
            <groupId>com</groupId>
            <artifactId>hutool-all</artifactId>
            <scope>system</scope>
            <version>4.5.9</version>
            <systemPath>${project.basedir}/lib/hutool-all-4.5.9.jar</systemPath>
        -->
        <!--辅助工具类 maven仓库引入方式-->
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>4.5.9</version>
        </dependency>

    </dependencies>

</project>
  

 

 

maven: clean-->compile-->package

No hutool.jar

2. Solve

The guess is that the packaging elements are missing in pom.xml

Add build plugin

<?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>com</groupId>
    <artifactId>EnctyptParamTool</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <java.version>1.8</java.version>
        <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <fastjson.version>1.2.32</fastjson.version>
    </properties>
    <dependencies>
        
        <!--辅助工具类-->
        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
            <version>4.5.9</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <!--这部分可有可无,加上的话则直接生成可运行jar包-->
                    <!--<archive>-->
                    <!--<manifest>-->
                    <!--<mainClass>${exec.mainClass}</mainClass>-->
                    <!--</manifest>-->
                    <!--</archive>-->
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
 

Execute in maven

Result (depending on the package has been entered, but become a class):

 

 3. Into the jar package

Modify the plugin configuration

C:\Users\Lenovo\.m2\repository\org\apache\maven\plugins\maven-assembly-plugin\2.2-beta-5

 

 

 Open with winzip, and drag the jar-with-dependencies.xml file (press and hold the left mouse button) out, modify the unpack to false

Drag the modified file into the compressed package

Repack

result:

 

Categories:  javaspring cloud

Guess you like

Origin blog.csdn.net/xiaokanfuchen86/article/details/113919617