2016-07-14 49 views
1

所以我试图将两个本地jar文件包含到我有的Maven项目中,但没有这样做。我尝试了解这些线程中的解决方案:12但它仍然没有工作。这里是我的pom.xml文件的关键部分:在maven项目中包含本地jar文件 - 找不到文件

<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文件位于资源文件夹中,正好位于基本目录下。

这就是设置。现在,当我尝试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正是在资源文件夹中。另外,我已经尝试了将它们与系统范围一起导入的方法,但这不适合我的目的,因为我希望它们包含在战争工件中。

非常感谢!

+0

你有文件在这里file:///Users/mlab/Desktop/2016/project_web/resources/edu/mlab/jar1/jar1_local/jar1_local-1.0.jar? – davidxxx

+0

不,我不这样做,但是不是包装宣言应该照顾的吗? –

+0

我重新编辑了路径。不,Maven search jar在groupId/artifactId/artifactId-version.jar中,其中必须将每个点字符的目录拆分为groupid。 试试:) – davidxxx

回答

1
  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 \ setting中指定s.xml例如

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

    <dependency> 
        <groupId>your.groupId</groupId> 
        <artifactId>your-artifactId</artifactId> 
        <version>your-version</version> 
    </dependency> 
    
  • +0

    看这如果我想创建一个战争神器这仍然成立? –

    +0

    这两个jar文件将被包含在war文件的WEB-INF/lib中。 –

    +0

    好的,在这种情况下,我想设置的groupID/artifactID是什么? –

    1

    假设:您使用Windows和你jar1 & jar2在C :\ Users \ yourusername folder

    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的行家-3.3.9 \的conf \设置。XML如下 enter image description here

    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

  • 验证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\

  • 打开文件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> 
    
    相关问题