1

I have created several projects in Java that I would like to package as group. I have created a wrapper project to hold these. So we pretty much have a set up like this

  • Project 1 - Has dependencies on ThirdPartyProject1
  • Project 2 - Has dependencies on ThirdPartyProject2
  • Project 3 - Has dependencies on ThirdPartyProject3
  • WrapperProject - Has dependencies on Project1, Project2, and Project3.

We are packaging a project that uses the WrapperProject and my supervisors would like to package the third party dependencies in separate file than the WrapperProject.jar that would be produced during the assembly.

I wonder whether that is possible and how? I have been looking into the Maven dependency plugin but have not used it before and so I am not quite sure how it works. At the end of the day I would like to have a lib folder and a Jar file that would look something like this.

Lib - ThirdPartyProject1.jar - ThirdPartyProject2.jar - ThirdPartyProject3.jar

WrapperProject.jar - Project1.jar - Project2.jar - Project3.jar

4

2 回答 2

1

您可以使用复制资源插件来创建 /target/lib 文件夹。或者您可以使用程序集插件来创建所有依赖项的 jar/zip。我不确定您在使用 lib 目录做什么,但将其作为 zip 文件可能更方便。

于 2013-11-14T03:01:11.430 回答
0

如果第三方 jar 在 maven 存储库中可用,那么您可以使用正常的 maven 构建命令“mvn package”,否则 jar 是项目特定的自定义 jar,那么您应该使用命令“mvn install”将该 jar 安装到您的 maven 本地存储库中”。请参考以下链接,

http://www.mkyong.com/maven/how-to-include-library-manully-into-maven-local-repository/

完成后,将该依赖项和以下构建配置包含到您的 pom.XML 中,然后更改主类。

 <build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>fully.qualified.MainClass</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build> 

现在构建项目,然后你会得到两个 jar 一个没有依赖项,另一个是依赖类。

于 2013-11-14T07:08:39.977 回答