在 pom.xml 配置本地 jar
Configure local jar in 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
s 放在这个文件夹中:
/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]
我错过了什么?
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
我认为仅仅复制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
)。
您可以将本地 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>
本地为你工作 above.If 你想把这个本地 jar 打包到你的 fat jar 然后在 maven 插件配置中包含以下行:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
在我的 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
s 放在这个文件夹中:
/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]
我错过了什么?
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
我认为仅仅复制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
)。
您可以将本地 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>
本地为你工作 above.If 你想把这个本地 jar 打包到你的 fat jar 然后在 maven 插件配置中包含以下行:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>