Using Maven to print directly running jar package

Time:2021-3-2

Add the following contents to the POM file under the project > build > plugins node

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <mainClass>com.taobao.search.abc.Xyz</mainClass>
            </manifest>
        </archive>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
</plugin>

Mainclass is your program entry main method.

Then go to the project directory and run:

mvn clean compile assembly:single 

If there are no errors, after compiling, there will be a file named XXXX jar with- dependencies.jar The file is lying quietly under the target folder.

java -jar xxxx-jar-with-dependencies.jar

You can run it directly.

Recommended Today

Rust and python: why rust can replace Python

In this guide, we compare the rust and python programming languages. We will discuss the applicable use cases in each case, review the advantages and disadvantages of using rust and python, and explain why rust might replace python. I will introduce the following: What is rust? What is Python? When to use rust When to […]