我想使用 Maven 从我的 libs 项目文件夹中加载所有 JAR [英] I want to load all JARs from my libs project folder with Maven

查看:33
本文介绍了我想使用 Maven 从我的 libs 项目文件夹中加载所有 JAR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 Maven 的 Java 项目.在我的项目中,我有一个名为 libs 的文件夹,其中包含我无法从 Internet/外部存储库加载的所有 JAR.

I have a Java project using Maven. In my project I have a folder called libs that contains all the JARs that I can't load from internet/external repository.

我的问题是如何指定 Maven 在打包、构建等过程中包含这些 JAR?

My issue is how to specify to Maven to include those JARs during packaging, building etc.?

Maven 新手,抱歉,这是一个愚蠢的问题.

New to Maven, sorry if it is a stupid question.

我有一个自动工具,可以在我的 Git 上查找我的 pom.xml 以构建 &在不同的环境中部署我的项目.因此,按照建议将其添加到本地 Maven 存储库中此处 无济于事,因为它只能在我的 PC 上运行.如果我在 JAR 中添加一个 libs 文件夹,它可以在任何地方工作.

EDIT : I have an automatic tool that will look up at my pom.xml on my Git to build & deploy my project on different environments. So adding it in local Maven repo, as suggested here will not help since it will work only on my PC. If I add a libs folder with my JARs it will work wherever I am.

如果有什么不清楚或者我弄错了,请在评论中问我.

Ask me in comments if it's not clear or if I'm mistaken.

推荐答案

与您的 EDIT 添加到本地 Maven 存储库相反 帮助并且它可以如下自动化:

Contrary to your EDIT adding to the local Maven repo will help and it can be automated as follows:

  • See jtahlborn's answer to Multiple install:install-file in a single pom.xml. (The current version of the maven-install-plugin is 2.5.2. I'd use that rather than the default.)
  • The <configuration>s should look like:

  <configuration>
    <file>${project.basedir}/path/to/your/libs/lib-X.jar</file>
    <repositoryLayout>default</repositoryLayout>

    <!-- match the dependency declaration for this artifact -->
    <groupId>logan.wlv</groupId>
    <artifactId>lib-X</artifactId>
    <version>x.y.z</version> 
    <packaging>jar</packaging>
    <!-- -------------------------------------------------- -->
  </configuration>

  • install-plugin 声明放入构建配置文件,例如lib.

    在每台新 PC 上运行 mvn initialize -P lib 一次(并且在 libs 的内容之后运行一次,因此 install-plugin 声明,已更改)在调用首先解决依赖关系的任何阶段之前,例如编译.

    Run mvn initialize -P lib once on every new PC (and once after the contents of libs, and hence the install-plugin declaration, changed) before invoking any phase that resolves dependencies first, e.g. compile.

    • 进一步自动化:

    • Automate this even further with:

      <profile>
        <id>lib</id>
        <activation>
          <file>
            <missing>${settings.localRepository}/logan/wlv/lib-X/x.y.z/lib-X-x.y.z.jar</missing>
          </file>
        </activation>
        ...
      <profile>
    

    这样就可以在第一次没有显式激活配置文件的情况下运行 mvn initialize.

    Such being able to run just mvn initialize without the explicit profile activation the very first time.

    这篇关于我想使用 Maven 从我的 libs 项目文件夹中加载所有 JAR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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