java项目打包,如何将使用到的jar包打入到项目的jar包中(适用于不方便添加lib到目标服务的情况)

项目的 pom.xml 增加插件

<build>
    <plugins>
        
        <plugin>
            <groupId>org.apache.maven.pluginsgroupId>
            <artifactId>maven-compiler-pluginartifactId>
            <configuration>
                <source>1.7source>
                <target>1.7target>
            configuration>
        plugin>

        
        <plugin>
            <groupId>org.apache.maven.pluginsgroupId>
            <artifactId>maven-dependency-pluginartifactId>
            <executions>
                <execution>
                    <id>copy-dependenciesid>
                    <phase>prepare-packagephase>
                    <goals>
                        <goal>copy-dependenciesgoal>
                    goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/liboutputDirectory>
                        <overWriteReleases>falseoverWriteReleases>
                        <overWriteSnapshots>falseoverWriteSnapshots>
                        <overWriteIfNewer>trueoverWriteIfNewer>
                    configuration>
                execution>
            executions>
        plugin>

        
        <plugin>
            <groupId>org.apache.maven.pluginsgroupId>
            <artifactId>maven-assembly-pluginartifactId>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependenciesdescriptorRef>
                descriptorRefs>
            configuration>
        plugin>

        <plugin>
            <groupId>org.apache.maven.pluginsgroupId>
            <artifactId>maven-surefire-pluginartifactId>
            <configuration>
                <skip>trueskip>
            configuration>
        plugin>

        <plugin>
            <groupId>org.apache.maven.pluginsgroupId>
            <artifactId>maven-shade-pluginartifactId>
            <executions>
                <execution>
                    <phase>packagephase>
                    <goals>
                        <goal>shadegoal>
                    goals>
                    <configuration>
                        <filters>
                            <filter>
                                <artifact>*:*artifact>
                                <excludes>
                                    <exclude>META-INF/*.SFexclude>
                                    <exclude>META-INF/*.DSAexclude>
                                    <exclude>META-INF/*.RSAexclude>
                                excludes>
                            filter>
                        filters>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                
                                <mainClass>com.liuyz.client.MyServiceClientmainClass>
                            transformer>
                        transformers>
                    configuration>
                execution>
            executions>
        plugin>
        

    plugins>
build>

maven 插件运行打包命令 package

java项目打包,如何将使用到的jar包打入到项目的jar包中(适用于不方便添加lib到目标服务的情况)_第1张图片

然后就可以在 target 文件夹内看到项目jar、源项目jar、lib

java项目打包,如何将使用到的jar包打入到项目的jar包中(适用于不方便添加lib到目标服务的情况)_第2张图片

你可能感兴趣的:(java后端,java,jar,maven)