Maven的指定类路径 [英] Specifiy classpath for maven

查看:445
本文介绍了Maven的指定类路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的Maven很新,所以让我先解释一下我要做什么:

Quite new to maven here so let me explain first what I am trying to do:

我们有某些JAR文件,这些文件不会添加到存储库中.这是因为它们特定于Oracle ADF,并且已经放置在我们的应用程序服务器上.任何时候任何应用程序都只能使用一种版本.为了进行编译,我们需要将它们放在类路径中.这些JARS有很多,因此,如果我们要升级到ADF的较新版本,则必须进入每个应用程序并重新定义一些非常冗余的依赖项.再说一遍,我的目标是将这些JAR添加到类路径中,因为我们将控制在其他地方实际使用的版本.

We have certain JAR files which will not be added to the repo. This is because they are specific to Oracle ADF and are already placed on our application server. There is only 1 version to be used for all apps at anyone time. In order to compile though, we need to have these on the class path. There are a LOT of these JARS, so if we were to upgrade to a newer version of ADF, we would have to go into every application and redefine some pretty redundant dependencies. So again, my goal is to just add these JARs to the classpath, since we will control what version is actually used elsewhere.

因此,基本上,我只想在给定的网络目录(开发人员无权对其进行修改)中将每个JAR添加到maven的类路径中,以进行编译.并且无需将任何这些JAR文件放在存储库中.当然,这些JAR不能打包到任何EAR/WAR中.

So basically, I want to just add every JAR in a given network directory (of which devs do not have permission to modify) to maven's classpath for when it compiles. And without putting any of these JAR files in a repository. And of course, these JARs are not to be packaged into any EAR/WAR.

为什么我不想将这些添加到公司回购中的其他原因是:

Amongst other reasons why I do not want to add these to the corporate repo is that:

  1. 这些JAR未被其他任何人使用.其中有很多,是Oracle罕见和专有的.
  2. 任何时候都只会使用给定JAR的一个版本.应用程序A依赖于1.0,应用程序B依赖于1.1永远不会发生. App A和B都将仅依赖于1.1或1.2.
  3. 我们计划维护100多个应用程序.这有很多pom.xml文件,这意味着每次我们升级Oracle ADF时,如果未正确指定任何依赖项(通过人为错误),则每次编辑该100多个pom.xml文件时,我们都必须修复每个错误.升级.

推荐答案

我看到三个选项:

  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).

这篇关于Maven的指定类路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆