在pom.xml中配置本地jar

时间:2018-08-02 08:35:02

标签: java maven pom.xml

在我的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文件夹。然后,将jar放在此文件夹中:

/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]

我想念什么?

3 个答案:

答案 0 :(得分:3)

我认为仅复制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)的路径。

答案 1 :(得分:1)

        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

答案 2 :(得分:0)

您可以将本地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>

Local可以通过上面的步骤为您工作。如果您想将此本地jar打包到胖jar中,请在maven插件配置中添加以下行:

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