0

I'm currently working with a Legacy app, whose process for building plugins requires adding dependencies on about 150 non-maven (ant I believe?) jar files. Ideally, I'd like to package these 150-jars into a single JAR, place it on Artifactory, and use that as a maven-dependency so that my team can more easily setup their development environment.

I've been experimenting with one-jar, maven-assembly-plugin, and maven-shade-plugin, which appears to just create one jar that contains several other jars (i.e. unzip the contents). However when adding that jar as a maven dependency, maven appears unable to resolve the contents/dependencies within these "sub-jars."

The code below is only an example of something I've tried; so feel free to suggest other approaches.

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.company</groupId>
    <artifactId>some-jars</artifactId>
    <packaging>jar</packaging>
    <version>1.0.0</version>
    <name>someName</name>

    <properties>
        <jdk.version>1.8</jdk.version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.mycompany.mypackage.MyMainClass</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.dstovall</groupId>
                <artifactId>onejar-maven-plugin</artifactId>
                <version>1.4.4</version>
                <executions>
                    <execution>
                        <configuration>

                            <binlibs>
                                <fileSet>
                                    <directory>${basedir}/jars</directory>
                                    <includes>
                                        <include>*</include>
                                    </includes>
                                </fileSet>
                            </binlibs>
                            <!-- Optional, default is false -->
                            <attachToBuild>true</attachToBuild>
                            <!-- Optional, default is "onejar" -->
                            <classifier>onejar</classifier>
                        </configuration>
                        <goals>
                            <goal>one-jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <pluginRepositories>
        <pluginRepository>
            <id>onejar-maven-plugin.googlecode.com</id>
            <url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
        </pluginRepository>
    </pluginRepositories>

</project>
4

2 回答 2

0

前段时间我有同样的问题

出于这个原因,我实现了maven-bulk-deploy,这使得 BOM 方法更容易实现

只需将 jar 放在一个文件夹中,选择一个 common-group-id/version(例如,与您的主项目相同)运行插件,它将创建一个 BOM 文件(即 pom)并将所有 jar 部署到您的资产中回购

随时结帐/分叉项目以尝试解决您的问题

于 2015-04-14T21:57:52.647 回答
0

也许您可能想考虑 Spring IO 平台(http://platform.spring.io/platform/#quick-start)采用的 BOM 方法,Maven 中的 JBoss Java EE 6 规范依赖项(http://www.andygibson.网络/博客/quickbyte/jboss-java-ee-6-spec-dependency-in-maven/

通过使用 BOM 方法,无需将所有库捆绑到一个 jar 中。

于 2015-04-14T21:37:24.533 回答