繁体   English   中英

在Maven项目中包括本地jar文件-找不到文件

[英]Include local jar file in maven project - not finding file

因此,我试图将两个本地jar文件包含到我拥有的Maven项目中,但未能这样做。 我已经尝试过以下线程中的解决方案: 1 2,但是它仍然没有真正起作用。 这是我的pom.xml文件的关键部分:

    <repository>
        <id>local-maven-repo</id>
        <url>file://${basedir}/resources</url>
    </repository>

然后是依赖项:

    <dependency>
        <groupId>edu.mlab.jar1</groupId>
        <artifactId>jar1_local</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>edu.mlab.jar2</groupId>
        <artifactId>jar2_local</artifactId>
        <version>1.0</version>
    </dependency>

这两个jar文件都分别在edu.mlab.jar1edu.mlab.jar2处包含程序包声明,所以这就是我想要的地方。 jar文件位于resources文件夹中,并且位于基本目录下。

这就是设置。 现在,当我尝试mvn package (在mvn clean )时,出现以下错误

[ERROR] Failed to execute goal on project PROJECT: Could not resolve dependencies for project edu.mlab.project:PROJECT:war:1.0-SNAPSHOT: The following artifacts could not be resolved: edu.mlab.jar1:jar1_local:jar:1.0, edu.mlab.jar2:jar2_local:jar:1.0: Failure to find edu.mlab.jar1:jar1_local:jar:1.0 in file:///Users/mlab/Desktop/2016/project_web/resources was cached in the local repository, resolution will not be reattempted until the update interval of local-maven-repo has elapsed or updates are forced -> [Help 1]

我不太确定发生了什么问题,因为jar1和jar2完全位于resources文件夹中。 另外,我尝试了使用系统范围导入它们的方法,但是由于我希望将它们包含在战争工件中,因此这对我来说不起作用。

非常感谢!

  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

参考网址: http : //maven.apache.org/plugins/maven-install-plugin/examples/specific-local-repo.html

注意:您的本地Maven存储库在安装$ M2_HOME \\ conf \\ settings.xml中指定,例如

<localRepository>C:\local_maven_repo</localRepository>
  1. 然后使用常规的Maven标签

     <dependency> <groupId>your.groupId</groupId> <artifactId>your-artifactId</artifactId> <version>your-version</version> </dependency> 

假设:您使用的是Windows而jar1和jar2位于C:\\ Users \\ yourusername文件夹中

  1. 设置您的M2_HOME环境变量,例如

    C:\\Users\\yourusername>set M2_HOME=C:\\apache-maven-3.3.9 C:\\Users\\yourusername>echo %M2_HOME% C:\\apache-maven-3.3.9

  2. 手动创建文件夹C:\\ local_maven_repo,然后编辑编辑文件

    C:\\ apache-maven-3.3.9 \\ conf \\ settings.xml如下 在此处输入图片说明

  3. 运行mvn命令将jar1和jar2安装到C:\\ local_maven_repo,例如

C:\\Users\\yourusername>mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=jar1.jar -DgroupId=edu.mlab -DartifactId=jar1 -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=C:\\local_maven_repo

C:\\Users\\yourusername>mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=jar2.jar -DgroupId=edu.mlab -DartifactId=jar2 -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=C:\\local_maven_repo

  1. 验证jar1和jar2在C:\\ local_maven_repo中,例如

C:\\Users\\yourusername>dir C:\\local_maven_repo\\edu\\mlab\\jar1\\1.0\\

C:\\Users\\yourusername>dir C:\\local_maven_repo\\edu\\mlab\\jar2\\1.0\\

  1. 打开文件C:\\ local_maven_repo \\ edu \\ mlab \\ jar1 \\ 1.0 \\ jar1-1.0.pom和C:\\ local_maven_repo \\ edu \\ mlab \\ jar2 \\ 1.0 \\ jar2-1.0.pom

文件:C:\\ local_maven_repo \\ edu \\ mlab \\ jar1 \\ 1.0 \\ jar1-1.0.pom

  <groupId>edu.mlab</groupId>
  <artifactId>jar1</artifactId>
  <version>1.0</version>

文件:C:\\ local_maven_repo \\ edu \\ mlab \\ jar2 \\ 1.0 \\ jar2-1.0.pom

  <groupId>edu.mlab</groupId>
  <artifactId>jar2</artifactId>
  <version>1.0</version>

复制以下内容并将其包含在pom.xml中,如下所示

<dependency>
  <groupId>edu.mlab</groupId>
  <artifactId>jar1</artifactId>
  <version>1.0</version>
<dependency>
<dependency>
  <groupId>edu.mlab</groupId>
  <artifactId>jar2</artifactId>
  <version>1.0</version>
<dependency>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM