2013-09-11 93 views
33

背景

试图用干净的安装Apache Maven的3.1.0的Java库添加到本地Maven仓库,与Java 1.7。下面是如何加入的Java归档文件:项目的POM缺失,没有依赖资料

mvn install:install-file \ 
    -DgroupId=net.sourceforge.ant4x \ 
    -DartifactId=ant4x \ 
    -Dversion=0.3.0 \ 
    -Dfile=ant4x-0.3.0.jar \ 
    -Dpackaging=jar 

此创建以下目录结构:

$HOME/.m2/repository/net/sourceforge/ant4x/ 
├── 0.3.0 
│ ├── ant4x-0.3.0.jar.lastUpdated 
│ └── ant4x-0.3.0.pom.lastUpdated 
└── ant4x 
    ├── 0.3.0 
    │ ├── ant4x-0.3.0.jar 
    │ ├── ant4x-0.3.0.pom 
    │ └── _remote.repositories 
    └── maven-metadata-local.xml 

该项目的pom.xml文件引用了相关项目(上面的树)如下:

<properties> 
    <java-version>1.5</java-version> 
    <net.sourceforge.ant4x-version>0.3.0</net.sourceforge.ant4x-version> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 
... 
<dependency> 
    <groupId>net.sourceforge</groupId> 
    <artifactId>ant4x</artifactId> 
    <version>${net.sourceforge.ant4x-version}</version> 
    <scope>provided</scope> 
</dependency> 

问题

运行后mvn compile,返回下列错误(full log on Pastebin):

[ERROR] Failed to execute goal on project ant4docbook: Could not resolve dependencies for project net.sourceforge:ant4docbook:jar:0.6-SNAPSHOT: Failure to find net.sourceforge:ant4x:jar:0.3.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1] 

documentation音符一系列可能出现的问题,但是,没有这些看起来适用。

想法

我尝试以下,按照文档:

  1. 复制默认设置用户的主目录的Maven:
     
    cp /opt/apache-maven-3.1.0/conf/settings.xml $HOME/.m2/.
  2. 编辑用户的settings.xml文件。
  3. 更新本地存储库的值:
     
    ${user.home}/.m2/repository
  4. 保存该文件。

我也尝试下面的命令:

mvn -U 
mvn clear -U 

我使用Maven 3.0.5尝试过,但失败了。

问题

你如何强制Maven来使用这个库的本地版本,而不是试图去寻找一个库,尚未提供下载?

相关

未解决该问题相关的问题和信息:

回答

14

变化:

<!-- ANT4X --> 
<dependency> 
    <groupId>net.sourceforge</groupId> 
    <artifactId>ant4x</artifactId> 
    <version>${net.sourceforge.ant4x-version}</version> 
    <scope>provided</scope> 
</dependency> 

要:

<!-- ANT4X --> 
<dependency> 
    <groupId>net.sourceforge.ant4x</groupId> 
    <artifactId>ant4x</artifactId> 
    <version>${net.sourceforge.ant4x-version}</version> 
    <scope>provided</scope> 
</dependency> 

net.sourceforgegroupId是不正确的。正确的值是net.sourceforge.ant4x

+0

我找不到任何这样的工件注册与maven。我尝试添加这个我的mavne,但它仍然无法工作。例外:缺少神器net.sourceforge.ant4x:ant4x:jar:0.3.0:提供。你确定? – gyan

+0

这是因为Maven试图在中央repo(可在互联网上)或本地repo(在pom配置文件中配置)中找到任何jar。在这个地方的以太网上,这个jar应该在那里,或者可以使用** maven:install **命令来安装它。 – gyan

2

范围<scope>provided</scope>让你有机会告诉jar在运行时可用,所以不要捆绑它。这并不意味着你在编译时不需要它,因此maven会尝试下载它。

现在我想,下面的maven神器根本就不存在。我试图搜索谷歌,但无法找到。因此你得到这个问题。

groupId更改为<groupId>net.sourceforge.ant4x</groupId>以获得最新的jar。

<dependency> 
    <groupId>net.sourceforge.ant4x</groupId> 
    <artifactId>ant4x</artifactId> 
    <version>${net.sourceforge.ant4x-version}</version> 
    <scope>provided</scope> 
</dependency> 

编辑:

这个问题的解决方案,该解决方案之一是

  1. 运行你自己的Maven的回购协议。
  2. 下载jar
  3. 将jar安装到版本库中。

  • 在你的pom.xml像添加代码。

    where http://localhost/repo is your local repo URL 
    <repositories> 
        <repository> 
         <id>wmc-central</id> 
         <url>http://localhost/repo</url> 
        </repository> 
    ..................... Other repository config ...................... 
    </repositories> 
    
  • +2

    使用Eclipse直接将jar添加到classpath的建议并不能解决Maven问题。如果有人使用这种方法,那么他们基本上放弃尝试使用Maven作为构建工具。 – twindham

    +0

    @twindham我同意早些时候的回答是一种破解,真的不是一个好习惯。我已经用更多的选项更新了答案,这个选项被广泛使用。 – gyan

    +0

    很好的编辑,这个新的答案绝对是一个解决方案,允许用户继续使用maven作为他们的构建工具。 – twindham

    相关问题