且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Maven的指定类路径

更新时间:2023-01-10 11:36:48

我看到三个选项:

  1. 将依赖项放入存储库中(可以是文件存储库,如
  1. Put the dependencies in a repository (could be a file repository as described in this answer) and declare them with a scope provided.
  2. Use the dirty system scope trick (i.e. declare the dependencies with a system scope and set the path to the jars in your file system.
  3. Little variation of #2: create a jar with a MANIFEST.MF referencing all the jars (using a relative path) and declare a dependency on this almost empty jar with a system scope.

干净的方法是选择#1,但其他方法在您的情况下也可以使用.选项#3似乎是您所寻找的最接近的东西.

The clean way is option #1 but others would work too in your case. Option #3 seems be the closest to what you're looking for.

更新:要阐明选项#3

假设您有一个包含 a.jar b.jar 的目录.创建一个 c.jar ,并在META-INF/MANIFEST.MF列表中的Class-Path条目中列出其他罐子,如下所示:

Let's say you have a directory with a.jar and b.jar. Create a c.jar with a Class-Path entry in its META-INF/MANIFEST.MF listing other jars, something like this:

Class-Path: ./a.jar ./b.jar 

然后在具有system范围的c(并且仅在c)上的POM中声明一个依赖项,其他jar将变为可见",而无需在您的POM中明确列出它们(请确保您需要在清单中声明它们,但这可以很容易地编写为脚本).

Then declare a dependency in your POM on c (and only on c) with a system scope, other jars will become "visible" without having to explicitly list them in your POM (sure, you need to declare them in the manifest but this can be very easily scripted).