普通的maven项目,如何打成一个fat jar(包括了全部依赖jar包)?

1、前言

用过spring boot的同学肯定知道,现在web项目可以直接打成jar包运行,相当方便。

那么普通项目如何配置(非spring boot),才能打成一个类似的jar包呢?

 

2、解决方案:

在pom中的build中进行如下配置即可:

        <plugins>
            <plugin>
                <artifactId>maven-assembly-pluginartifactId>
                <configuration>
                    <archive>
                        <manifest>
                            
                            <mainClass>netty.client.TcpClient809mainClass>
                        manifest>
                    archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependenciesdescriptorRef>
                    descriptorRefs>
                configuration>
                <executions>
                    <execution>
                        <id>make-assemblyid> 
                        <phase>packagephase> 
                        <goals>
                            <goal>singlegoal>
                        goals>
                    execution>
                executions>
            plugin>
        plugins>

 

3、普通java工程,如何获取所有依赖的jar包

If you need to download the jars instead of using a build system, create a Maven pom file like this with the desired version:

xml version="1.0"?>
<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.0modelVersion>
    <groupId>com.netflix.hystrix.downloadgroupId>
    <artifactId>hystrix-downloadartifactId>
    <version>1.0-SNAPSHOTversion>
    <name>Simple POM to download hystrix-core and dependenciesname>
    <url>http://github.com/Netflix/Hystrixurl>
    <dependencies>
        <dependency>
            <groupId>com.netflix.hystrixgroupId>
            <artifactId>hystrix-coreartifactId>
            <version>x.y.zversion>
            <scope/>
        dependency>
    dependencies>
project>

 

Then execute:

mvn -f download-hystrix-pom.xml dependency:copy-dependencies

It will download hystrix-core-*.jar and its dependencies into ./target/dependency/.

You need Java 6 or later.

你可能感兴趣的:(普通的maven项目,如何打成一个fat jar(包括了全部依赖jar包)?)