使用Maven pom标签

时间:2015-10-29 06:01:38

标签: java maven-3 opendaylight

我有一个关于Maven pom.xml的问题。

我在pom.xml中添加依赖,如:

<dependencies>
    <dependency>
            <groupId>org.opendaylight.controller</groupId>
            <artifactId>features-restconf</artifactId>
            <version>1.2.1-Lithium-SR1</version>
            <classifier>features</classifier>
            <type>xml</type>
            <scope>runtime</scope>
    </dependency>
</dependencies>

我无法理解&lt;的用法分类器&gt;和&lt;输入&gt;。

我的问题是:

  
      
  1. 分类器类型
  2. 的含义是什么   
  3. 范围(运行时)的含义是什么,而类型是xml。我猜xml意味着maven需要一个xml文件,但它与它有什么关系   的运行时?我认为运行时始终与&#34;添加到类路径&#34;,但为什么是xml?
  4.   

如果我评论&lt;类型&gt;我得到了错误:

  

[错误]无法在项目测试中执行目标:无法解决   项目com.ruan的依赖项:test:jar:1.0-SNAPSHOT:失败   找   org.opendaylight.controller:功能 - restconf:罐子:特点:1.2.1-锂SR1   在http://nexus.opendaylight.org/content/repositories/public/中   缓存在本地存储库中,不会重新尝试解析   直到opendaylight-mirror的更新间隔已经过去或   强制更新 - &gt; [帮助1]

如果我评论&lt;分类器&gt;我得到了错误:

  

[错误]无法在项目测试中执行目标:无法解决   项目com.ruan的依赖项:test:jar:1.0-SNAPSHOT:失败   找   org.opendaylight.controller:features-restconf:xml:1.2.1-Lithium-SR1 in   缓存了http://nexus.opendaylight.org/content/repositories/public/   在本地存储库中,解决方案将不会重新尝试,直到   已经过了opendaylight-mirror的更新间隔或更新了   强迫 - &gt; [帮助1]

如果我正确运行,我得到的目录如下:

haoruan:~/.m2/repository/org/opendaylight/controller/features-restconf $ cd 1.2.1-Lithium-SR1/
total 96
-rw-r--r--  1 haoruan  staff   264B Oct 29 13:58 _remote.repositories
-rw-r--r--  1 haoruan  staff   397B Oct 29 13:38 features-restconf-1.2.1-Lithium-SR1-features.jar.lastUpdated
-rw-r--r--  1 haoruan  staff   9.0K Oct 29 13:58 features-restconf-1.2.1-Lithium-SR1-features.xml
-rw-r--r--  1 haoruan  staff    40B Oct 29 13:58 features-restconf-1.2.1-Lithium-SR1-features.xml.sha1
-rw-r--r--  1 haoruan  staff    12K Oct 29 13:38 features-restconf-1.2.1-Lithium-SR1.pom
-rw-r--r--  1 haoruan  staff    40B Oct 29 13:38 features-restconf-1.2.1-Lithium-SR1.pom.sha1
-rw-r--r--  1 haoruan  staff   397B Oct 29 13:39 features-restconf-1.2.1-Lithium-SR1.xml.lastUpdated

1 个答案:

答案 0 :(得分:0)

正如您的artifactId所示,您正在使用opendaylight控制器的features-restconf包含依赖项。

如果你在github repostory中检查控制器的代码:

https://github.com/opendaylight/controller/releases/tag/release%2Flithium-sr1

你会注意到有一个名为&#34;功能&#34;的目录。其中包含一个pom.xml文件。如果您打开该pom.xml文件,您可以看到它与artifactId features-controller对应,并且具有不同的模块:

<module>config</module>
<module>config-persister</module>
<module>config-netty</module>
<module>mdsal</module>
<module>netconf</module>
<module>protocol-framework</module>
<module>akka</module>
<module>netconf-connector</module>
<module>restconf</module>
<module>extras</module>

对于每个模块,在功能目录中都创建了一个子文件夹。对于每个子文件夹,下一个路径中都有一个features.xml:/src/main/resources/features.xml

因此,对于您发送的依赖项,您告诉pom的是,必须附加这些features.xml文件中指示的所有其他依赖项,并且在编译时不需要每个依赖项,但它们在执行时间(运行时)中是必需的。

有关每个pom.xml标记的含义的更多信息:

https://maven.apache.org/pom.html

在那里,你会读到:

<强>分类: 分类器允许区分从相同POM构建但其内容不同的工件。它是一些可选的任意字符串 - 如果存在 - 将附加到版本号之后的工件名称。

<强>范围: 此元素引用手头任务的类路径(编译和运行时,测试等)以及如何限制依赖项的传递性。     运行时 - &gt;此范围表示编译不需要依赖项,但是用于执行。它位于运行时和测试类路径中,但不是编译类路径。