是否有任何插件可以启用非 Maven 依赖项加载/使用?

发布于 2024-10-15 21:44:36 字数 1049 浏览 1 评论 0原文

我需要在我的项目中使用第三方JAR库(实际上它是 Dresden OCL for Eclipse),未作为 Maven 工件提供。相反,它只是一个可下载的 JAR 文件。我可以指示 Maven 使用此 JAR 文件,就像使用 一样吗?我想应该有一些插件用于此目的?

附注我只是不想将 35Mb 的第三方二进制文件添加到我的 SVN 存储库中。

以这种方式配置就好了:

<build>
  <plugins>
    <plugin>
      <groupId>com.example</groupId>
      <artifactId>non-maven-dependencies-injector</artifactId>
      <configuration>
        <libraries>
          <library>http://www.example.com/something*.jar</library>
          <library>http://www.example.com/something-else*.jar</library>
        </libraries>
      </configuration>
    </plugin>
  <plugins>
</build>

这个插件将 1) 下载这些 JAR 文件,2) 将它们作为依赖项添加到 pom.xml 中。也许这个插件可以将它们存储在 ~/.m2/temp/ 中的某个位置...

I need to use a third-party JAR library in my project (actually it's Dresden OCL for Eclipse) that is not provided as a Maven artifact. Instead, it's just a downloadable JAR file. Can I instruct Maven to use this JAR file the same way I'm using <dependencies>? I suppose that there should be some plugin for this purpose?

ps. I just don't want to add 35Mb of third-party binaries into my SVN repository.

Would be nice to have it configured this way:

<build>
  <plugins>
    <plugin>
      <groupId>com.example</groupId>
      <artifactId>non-maven-dependencies-injector</artifactId>
      <configuration>
        <libraries>
          <library>http://www.example.com/something*.jar</library>
          <library>http://www.example.com/something-else*.jar</library>
        </libraries>
      </configuration>
    </plugin>
  <plugins>
</build>

And this plugin would 1) download these JAR files, and 2) add them as dependencies into pom.xml. Maybe this plugin could store them somewhere in ~/.m2/temp/...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

走过海棠暮 2024-10-22 21:44:37

您可以将其安装在本地或将其部署到站点本地(例如公司范围)存储库。
如果您使用的依赖项 maven 在配置的存储库中找不到,它甚至会为您提供所需的命令:

然后,使用以下命令安装它:
mvn install:install-file -DgroupId=mygid -DartifactId=myaid -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file

或者,如果您托管自己的存储库,则可以在那里部署该文件:
mvn 部署:部署文件 -DgroupId=mygid -DartifactId=myaid -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

请注意:这样您只能将 .jar 添加到您的存储库中,将不会有 pom 一起指定临时依赖项。因此,如果您的第三方库有自己的依赖项,您必须将它们手动添加到您的 pom.xml 中,因为不会自动解析。

You can install it local or deploy it to your site-local (e.g. company-wide) repository.
If you use a dependency maven cannot find in the configured repositories, it even gives you the required commands:

Then, install it using the command:
mvn install:install-file -DgroupId=mygid -DartifactId=myaid -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file

Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=mygid -DartifactId=myaid -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]

Please note: This way you only add the .jar to your repository, there will be no pom along with it to specify transient dependencies. So if your third-party library has dependencies of it's own you'll have to add them manually to your pom.xml as there will be no automatic resolution.

陪我终i 2024-10-22 21:44:37

这里提到的“mvn install:install-file”将帮助您将 jar 安装到本地存储库中。但是,如果您想让这些 jar 文件随后自动可供项目的开发人员使用,请将相关部分复制到项目中每个人都可以使用的存储库,并使用标记使该存储库可用,例如通过将所有文件签入SVN。请参阅 http://code.google.com/p/codebistro/wiki/BuildNumber#例如,Maven_Plugin_Example 指的是 SVN 托管的存储库。

PS 祝 SV 旅途平安!

"mvn install:install-file" mentioned here will help you to install the jars into your local repository. However, if you want to make these jars subsequently available to the developers on the project automaticall, copy the relevant pieces to a repository available to everybody on the project and make this repository available using the tag, for example by checking all the files into the SVN. See http://code.google.com/p/codebistro/wiki/BuildNumber#Maven_Plugin_Example which refers to a SVN-hosted repository for example.

P.S. Have a safe trip to the SV!

肩上的翅膀 2024-10-22 21:44:37

这里有一种不同的方法,可以在项目目录中添加 Maven 存储库,将其用作 pom.xml 中的存储库,并在 SVN 上与签出该项目的任何人共享该存储库。 从这里交叉发布。

在您的项目目录中,创建一个名为 repo 的文件夹,我们将使用它作为基于文件夹的 Maven 存储库。

将以下文件存储库添加到您的项目 pom.xml

<repositories>
    <repository>
        <id>file.repo</id>
        <url>file://${project.basedir}/repo</url>
    </repository>
</repositories>

使用以下命令将外部 jar 部署到文件存储库:

mvn deploy:deploy-file
-Durl=file:///absolute/path/to/your-project/repo \
-DrepositoryId=file.repo \
-Dfile=path-to-your.jar \
-DgroupId=some.external.project.group \
-DartifactId=the-artifact-name \
-Dversion=1.0 \
-Dpackaging=jar;

接下来,您可以在项目中添加对 jar 的正常依赖项pom.xml,使用上面传递的 groupId、artifactId 和版本的值。然后,您可以将存储库文件夹添加到 SVN,并将更改提交到您的 pom.xml。现在,任何检查您的项目的开发人员都可以毫不费力地使用相同的依赖项。

Here's a different approach that'll let add a Maven repository inside the project directory, use that as a repository in you pom.xml, and share the repository on SVN with anyone checking out the project. Crosspost from here.

In your project directory, create a folder called repo, which we'll use as a folder based Maven repository.

Add the following file repository to your project pom.xml:

<repositories>
    <repository>
        <id>file.repo</id>
        <url>file://${project.basedir}/repo</url>
    </repository>
</repositories>

Deploy the external jar(s) to the file repository with the following command:

mvn deploy:deploy-file
-Durl=file:///absolute/path/to/your-project/repo \
-DrepositoryId=file.repo \
-Dfile=path-to-your.jar \
-DgroupId=some.external.project.group \
-DartifactId=the-artifact-name \
-Dversion=1.0 \
-Dpackaging=jar;

Following this you can just add a normal dependency on the jar in your project pom.xml, using the values for groupId, artifactId and version you passed above. You can then add the repo folder to SVN, and commit the changes to your pom.xml. Any developer checking out your project will now be able to use the same dependency without any effort.

不一样的天空 2024-10-22 21:44:37
I think the below answer will help you...just place jar files on your SVN and tell them all to e synch with SVN and here the ${lib.directory}    will be t he local path

 <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-install-plugin</artifactId>
                  <version>2.4</version>
                  <executions>
                      <execution>
                          <id>db2jcc9</id>
                          <phase>compile</phase>
                          <goals>
                              <goal>install-file</goal>
                          </goals>
                          <configuration>
                              <groupId>com.ibm</groupId>
                              <artifactId>db2jcc</artifactId>
                              <version>9</version>
                              <packaging>jar</packaging>
                              <file>${lib.directory}\db2jcc-9.jar</file>
                          </configuration>
                      </execution>
                      </executions>
    <plugin>
I think the below answer will help you...just place jar files on your SVN and tell them all to e synch with SVN and here the ${lib.directory}    will be t he local path

 <plugin>
                  <groupId>org.apache.maven.plugins</groupId>
                  <artifactId>maven-install-plugin</artifactId>
                  <version>2.4</version>
                  <executions>
                      <execution>
                          <id>db2jcc9</id>
                          <phase>compile</phase>
                          <goals>
                              <goal>install-file</goal>
                          </goals>
                          <configuration>
                              <groupId>com.ibm</groupId>
                              <artifactId>db2jcc</artifactId>
                              <version>9</version>
                              <packaging>jar</packaging>
                              <file>${lib.directory}\db2jcc-9.jar</file>
                          </configuration>
                      </execution>
                      </executions>
    <plugin>
七婞 2024-10-22 21:44:36

是的,您可以使用 maven-install 插件将其安装到本地存储库中。

mvn install:install-file -Dfile=your-artifact-1.0.jar \
                         -DgroupId=org.some.group \
                         -DartifactId=your-artifact \
                         -Dversion=1.0 \
                         -Dpackaging=jar \
                         -DgeneratePom=true

如果您希望其他团队成员能够下载此依赖项,而无需自己安装,则需要设置自己的工件存储库,并在那里部署工件使用 maven-deploy-plugin 的方式与在本地安装它的方式相同。

yes you can install it into your local repository with maven-install plugin

mvn install:install-file -Dfile=your-artifact-1.0.jar \
                         -DgroupId=org.some.group \
                         -DartifactId=your-artifact \
                         -Dversion=1.0 \
                         -Dpackaging=jar \
                         -DgeneratePom=true

If you want your other team members to be able to download this dependency without having to install it them thelves, you need to setup your own artifact repo, and deploy the artifact there with maven-deploy-plugin in same way as you installed it localy.

人间不值得 2024-10-22 21:44:36

是的。 maven-external-dependency- 支持此功能(使用非 Mavenized 依赖项)插件

示例:

<artifactItem>
    <groupId>jwbroek.cuelib</groupId>
    <artifactId>cuelib</artifactId>
    <version>${cuelib-version}</version>
    <packaging>jar</packaging>
    <downloadUrl>http://cuelib.googlecode.com/files/cuelib-${cuelib-version}.jar</downloadUrl>
    <checksum>d03b6b960b3b83a2a419e8b5f07b6ba4bd18387b</checksum>
</artifactItem>

它还可以从 zip 文件中提取工件

<artifactItem>
    <groupId>mediautil</groupId>
    <artifactId>mediautil</artifactId>
    <version>${mediautil-version}</version>
    <packaging>jar</packaging>
    <install>true</install>
    <force>false</force>
    <downloadUrl>http://downloads.sourceforge.net/project/mediachest/MediaUtil/Version%201.0/mediautil-1.zip</downloadUrl>
    <checksum>aa7ae51bb24a9268a8e57c6afe478c4293f84fda</checksum>
    <extractFile>mediautil-${mediautil-version}/mediautil-${mediautil-version}.jar</extractFile>
    <extractFileChecksum>e843cd55def75dce57123c79b7f36caca4841466</extractFileChecksum>
</artifactItem>

Yes. This (using non-Mavenized dependencies) is supported by the maven-external-dependency-plugin.

Example:

<artifactItem>
    <groupId>jwbroek.cuelib</groupId>
    <artifactId>cuelib</artifactId>
    <version>${cuelib-version}</version>
    <packaging>jar</packaging>
    <downloadUrl>http://cuelib.googlecode.com/files/cuelib-${cuelib-version}.jar</downloadUrl>
    <checksum>d03b6b960b3b83a2a419e8b5f07b6ba4bd18387b</checksum>
</artifactItem>

It can also extract artifacts from zip files:

<artifactItem>
    <groupId>mediautil</groupId>
    <artifactId>mediautil</artifactId>
    <version>${mediautil-version}</version>
    <packaging>jar</packaging>
    <install>true</install>
    <force>false</force>
    <downloadUrl>http://downloads.sourceforge.net/project/mediachest/MediaUtil/Version%201.0/mediautil-1.zip</downloadUrl>
    <checksum>aa7ae51bb24a9268a8e57c6afe478c4293f84fda</checksum>
    <extractFile>mediautil-${mediautil-version}/mediautil-${mediautil-version}.jar</extractFile>
    <extractFileChecksum>e843cd55def75dce57123c79b7f36caca4841466</extractFileChecksum>
</artifactItem>
信仰 2024-10-22 21:44:36

您可以在 pom.xml 中使用“system”范围来获取本地库依赖项:

system
此范围类似于
除非您必须
提供包含它的 JAR
明确地。神器永远是
可用并且未在
存储库。

系统路径
仅当依赖范围是系统时才使用。否则,如果设置了此元素,构建将会失败。路径必须是绝对路径,因此建议使用属性来指定特定于机器的路径(下面详细介绍属性),例如 ${java.home}/lib。由于假定系统范围依赖项已预先安装,因此 Maven 将不会检查项目的存储库,而是检查以确保文件存在。如果没有,Maven 将构建失败并建议您手动下载并安装。

<dependency>
    <groupId>some.id</groupId>
    <artifactId>artifact</artifactId>
    <version>1.2.3</version>
    <scope>system</scope>
    <systemPath>${basedir}/path/to/jarFile.jar</systemPath>
</dependency>

AFAIK,您几乎可以使用您想要的 groupId、artifactId 和 version。请参阅 Maven 系统依赖这个问题

You can use "system"-scope in your pom.xml for local library dependencies:

system
This scope is similar to
provided except that you have to
provide the JAR which contains it
explicitly. The artifact is always
available and is not looked up in a
repository.

systemPath
is used only if the the dependency scope is system. Otherwise, the build will fail if this element is set. The path must be absolute, so it is recommended to use a property to specify the machine-specific path (more on properties below), such as ${java.home}/lib. Since it is assumed that system scope dependencies are installed a priori, Maven will not check the repositories for the project, but instead checks to ensure that the file exists. If not, Maven will fail the build and suggest that you download and install it manually.

<dependency>
    <groupId>some.id</groupId>
    <artifactId>artifact</artifactId>
    <version>1.2.3</version>
    <scope>system</scope>
    <systemPath>${basedir}/path/to/jarFile.jar</systemPath>
</dependency>

AFAIK, you can use pretty much what you want for groupId, artifactId and version. See Maven System Depencies and this question.

许仙没带伞 2024-10-22 21:44:36

以您的示例 Dresden OCL 有超过 20 个 JAR 文件,并且您需要将其分发给许多开发人员,最好的解决方案是在某处安装存储库管理器(例如 nexus 或 artifactory),花点时间将这 20 个 jar 上传到该管理器存储库,并使用它们。最好的办法是将它们放入私有 groupId 中,因此,如果它们有时会发布到 m2 存储库,则不会出现名称冲突。

另一点是询问 Dresden OCL 维护者,他们是否可以提供 m2 存储库。现在 m2eclipse 是一个 eclipse 孵化器项目,这可能会让更多人感兴趣。

Taking that your example Dresden OCL has over 20 JAR files, and you need to distribute it to many developers, the best solution would be to install a repository manager somewhere (like nexus or artifactory), take your time to upload these 20 jars to that repository, and use them. Best bet would be to put them in a private groupId, so if they'll get published to a m2 repo sometime, you won't end up with name conflicts.

Another point, would be to ask the Dresden OCL Maintainers, if they can offer a m2 repository. Now that m2eclipse is an eclipse incubator project, this might interest more people.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文