【问题标题】:Configure local jar in pom.xml在 pom.xml 中配置本地 jar
【发布时间】:2018-08-02 08:35:01
【问题描述】:

在我的 maven 项目中,我需要使用一些本地 jar 库作为依赖项。

我正在尝试使用这种方法在pom.xml中配置它们:

<repositories>
    <repository>
        <id>projectName.local</id>
        <url>file://${project.basedir}/libs</url>
    </repository>
</repositories>

<dependencies>
    <dependency>
        <groupId>org.myproject</groupId>
        <artifactId>ProjectName</artifactId>
        <version>1.0</version>
    </dependency>

    <!-- other dependencies... -->
</dependencies>

我在项目根目录中定义了一个指向libs 文件夹的本地存储库。然后我把jars 放到了这个文件夹里:

/libs/org/myproject/ProjectName/1.0/ProjectName-1.0.jar

但是,在构建项目时我收到了这个警告:

The POM for org.myproject:ProjectName:jar:1.0 is missing, no dependency information available

这个构建失败的结果:

Failed to execute goal on project my_project: Could not resolve dependencies for project *** : The following artifacts could not be resolved: org.myproject:ProjectName:jar:1.0: Failure to find org.myproject:ProjectName:jar:1.0 in file://C:\Users\David\Documents\NetBeansProjects\my_project/libs was cached in the local repository, resolution will not be reattempted until the update interval of projectName.local has elapsed or updates are forced -> [Help 1]

我错过了什么?

【问题讨论】:

  • 开始使用仓库管理器上传jar包就搞定了...

标签: java maven pom.xml


【解决方案1】:

我认为仅仅复制 jar 文件并不能解决您的问题。您将需要使用 Maven 本身在该存储库中使用如下命令安装依赖项:

mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file  -Dfile=path-to-your-artifact-jar \
                -DgroupId=your.groupId \
                -DartifactId=your-artifactId \
                -Dversion=version \
                -Dpackaging=jar \
                -DlocalRepositoryPath=path-to-specific-local-repo

path-to-specific-local-repo 应该是本地存储库的路径 (file://${project.basedir}/libs)。

【讨论】:

  • 我正在关注这些教程:doduck.com/adding-local-jar-in-maven-local-repositoryroufid.com/3-ways-to-add-local-jar-to-maven-project(第三种方法),他们没有提到这一点
  • @davioooh 如何为要复制到存储库的 jar 文件创建 pom 描述符?
  • 这确实是正确的方法。或者,您也可以至少手动执行此操作,只需在包含您的依赖项工件信息的 Jar 旁边添加一个 ProjectName-1.0.pom
  • @gil.fernandes 对不起,你是对的!我试试看!
  • @gil.fernandes 谢谢!我也试过这个命令在本地 repo 中部署 jar:mvn deploy:deploy-file -Dfile=&lt;path-to-file&gt; -DgroupId=&lt;group-id&gt; -DartifactId=&lt;artifact-id&gt; -Dversion=&lt;version&gt; -Dpackaging=jar -Durl=file:./maven-repository/ -DrepositoryId=maven-repository -DupdateReleaseInfo=true 并且它可以工作。
【解决方案2】:
        Define the pom.xml like dependency.

                  <dependency>
                    <groupId>org.myproject</groupId>
                    <artifactId>ProjectName</artifactId>
                    <version>0.0.1-SNAPSHOT</version>
                    <scope>system</scope>
                    <systemPath>${project.basedir}/src/main/resources/jarfile</systemPath>
                </dependency>

      Put the all the files in the folder

【讨论】:

【解决方案3】:

您可以将本地 jar 添加为:

<dependency>
    <groupId>com.sample</groupId>
    <artifactId>sample</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/src/main/resources/Name_Your_JAR.jar</systemPath>
</dependency>

通过上述操作本地为您工作。如果您想将此本地 jar 打包到您的 fat jar 中,请在 maven 插件配置中包含以下行:

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <includeSystemScope>true</includeSystemScope>
  </configuration>
</plugin>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    • 2019-10-06
    • 1970-01-01
    • 2018-12-07
    • 2014-07-09
    • 2014-12-06
    相关资源
    最近更新 更多