【问题标题】:How to create only one executable jar with all dependencies inside it using maven shaded plugin instead of two如何使用maven shaded插件而不是两个创建一个包含所有依赖项的可执行jar
【发布时间】:2016-12-06 04:28:28
【问题描述】:
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>SoclePDCFDR</groupId>
    <artifactId>SoclePDCFDR</artifactId>
    <version>0.0.1-SNAPSHOT</version>



    <dependency>
        <groupId>ojdbc</groupId>
        <artifactId>ojdbc</artifactId>
        <version>14</version>
        <type>pom</type>
    </dependency>


<build>

    <!-- <sourceDirectory>src</sourceDirectory>
    <resources>
        <resource>
            <directory>src</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources> -->
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>2.4.3</version>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                       <finalName>Test</finalName>
                        <shadedArtifactAttached>true</shadedArtifactAttached>
                        <shadedClassifierName>jar-with-dependencies</shadedClassifierName>
                        <transformers>
                            <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <manifestEntries>
                                    <Main-Class>com.sfdr.ms.pdc.FilesManagementMain</Main-Class>
                                <Class-Path>.</Class-Path>
                                </manifestEntries>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

【问题讨论】:

    标签: java maven jakarta-ee jar maven-plugin


    【解决方案1】:

    请参考以下插件,

    <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>com.bitsWilp.BITSPilani</mainClass>
                            </manifest>
                        </archive>
                        <finalName>bitsWILP</finalName>
                        <appendAssemblyId>false</appendAssemblyId>
                    </configuration>
    </plugin>
    

    参考:https://github.com/ramasamykasiviswanathan/BITSWilpAPI/blob/newAPIimpl/pom.xml

    我为一个捆绑了所有依赖项的 API 编写代码。

    【讨论】:

    • 对我来说它仍在创建两个罐子,maven.apache.org/POM/4.0.0" xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:schemaLocation="maven.apache.org/POM/4.0.0 maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0SoclePDCFDRSoclePDCFDR0.0.1-SNAPSHOT 我在 pom.xml 的顶部添加了它的两个罐子名称 SoclePDCFDR-0.0.--快照和具有最终名称的快照
    • 你能把完整的内容分享给我吗,你在哪里打包,理想情况下它应该可以工作。
    • 嘿,刚刚检查了我的构建,最终名称是依赖打包到它的那个。
    猜你喜欢
    • 2011-04-12
    • 2016-06-04
    • 1970-01-01
    • 2021-12-25
    • 2014-01-08
    • 2015-09-14
    • 1970-01-01
    • 1970-01-01
    • 2019-11-15
    相关资源
    最近更新 更多