java – 具有依赖关系的Maven构建程序集

前端之家收集整理的这篇文章主要介绍了java – 具有依赖关系的Maven构建程序集前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有独立的 java应用程序,我想打包为:myapp.jar.并将所有相关的jar复制到“备用文件夹”.理想情况下,我想要将maven更新Meta-INF文件添加到其中的所有类路径依赖性jar文件.

例如,如果我的项目引用了commons.jar,并且当我使用此插件来构建程序集时,它将所有.class文件和程序包从commons.jar复制到myappjar-with-dependencies.jar中.

maven程序集插件的问题解决了所有依赖关系到myappjar-with-dependencies.jar中.

<plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <archive>
                    <manifest>
                        <mainClass>com.core.App</mainClass>
                    </manifest>
                </archive>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> 
                    <phase>package</phase> 
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>

解决方法

你可以试试看
<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>com.core.App</mainClass>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <configuration>
                <descriptors>
                    <descriptor>src/assembly/bin.xml</descriptor>
                </descriptors>
            </configuration>
        </plugin>

SRC /组件/ bin.xml

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
    <formats>
        <format>dir</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <dependencySets>
        <dependencySet>
            <outputDirectory>/</outputDirectory>
            <unpack>false</unpack>
            <includes>
                <include>${artifact}</include>
            </includes>
        </dependencySet>
        <dependencySet>
            <outputDirectory>/lib</outputDirectory>
            <unpack>false</unpack>
            <excludes>
                <exclude>${artifact}</exclude>
            </excludes>
        </dependencySet>
    </dependencySets>
</assembly>

运行它

mvn clean package assembly:single

详细信息:http://maven.apache.org/plugins/maven-assembly-plugin/index.html

原文链接:https://www.f2er.com/java/121260.html

猜你在找的Java相关文章