15.3. mvn URL Handler
15.3.1. 概述
如果使用 Maven 构建捆绑包,或者您知道特定捆绑包可从 Maven 存储库获得,您可以使用 Mvn 处理程序方案来定位捆绑包。
为确保 Mvn URL 处理程序可以找到本地和远程 Maven 工件,您可能会发现自定义 Mvn URL 处理程序配置的必要。详情请查看 第 15.3.5 节 “配置 Mvn URL 处理程序”。
15.3.2. 语法
Mvn URL 的语法如下:
mvn:[repositoryUrl!]groupId/artifactId[/[version][/[packaging][/[classifier]]]]
mvn:[repositoryUrl!]groupId/artifactId[/[version][/[packaging][/[classifier]]]]
其中 repositoryUrl (可选)指定 Maven 存储库的 URL。groupId,artifactId,version,packaging , 和 classifier 是标准的 Maven 协调,用于定位 Maven 工件。
15.3.3. 省略协调
当指定 Mvn URL 时,只需要 groupId 和 artifactId 协调。以下示例引用了带有 groupId、org.fusesource.example
的 Maven 捆绑包,以及 artifactId,bundle-demo
:
mvn:org.fusesource.example/bundle-demo mvn:org.fusesource.example/bundle-demo/1.1
mvn:org.fusesource.example/bundle-demo
mvn:org.fusesource.example/bundle-demo/1.1
当省略了 版本时,如第一个示例所示,默认为 LATEST
,它根据可用的 Maven 元数据解析为最新版本。
要在没有指定 打包 或 版本 值的情况下指定 分类器 值,最好在 Mvn URL 中留下差距。同样,如果您要指定没有 version 值的 打包 值。例如:
mvn:groupId/artifactId///classifier mvn:groupId/artifactId/version//classifier mvn:groupId/artifactId//packaging/classifier mvn:groupId/artifactId//packaging
mvn:groupId/artifactId///classifier
mvn:groupId/artifactId/version//classifier
mvn:groupId/artifactId//packaging/classifier
mvn:groupId/artifactId//packaging
15.3.4. 指定版本范围
在 Mvn URL 中指定 版本 值时,您可以指定一个版本范围(使用标准 Maven 版本范围语法)来代替简单的版本号。您可以使用方括号[
和 ]
- 表示包含范围和括号(
和 )
- 表示专用范围。例如,范围 [1.0.4,2.0)
匹配任何版本 v
,它满足 1.0.4 categories v < 2.0
。您可以在 Mvn URL 中使用这个版本范围,如下所示:
mvn:org.fusesource.example/bundle-demo/[1.0.4,2.0)
mvn:org.fusesource.example/bundle-demo/[1.0.4,2.0)
15.3.5. 配置 Mvn URL 处理程序
首次使用 Mvn URL 之前,您可能需要自定义 Mvn URL 处理程序设置,如下所示:
15.3.6. 检查 Mvn URL 设置
Mvn URL 处理程序解析对本地 Maven 存储库的引用,并维护远程 Maven 存储库列表。解析 Mvn URL 时,处理程序会首先搜索本地存储库,然后搜索远程存储库以查找指定的 Maven 模版。如果解析 Mvn URL 存在问题,您应该首先检查处理器设置,以查看处理器设置以查看它用于解析 URL 的本地存储库和远程存储库。
要检查 Mvn URL 设置,请在控制台中输入以下命令:
JBossFuse:karaf@root> config:edit org.ops4j.pax.url.mvn JBossFuse:karaf@root> config:proplist
JBossFuse:karaf@root> config:edit org.ops4j.pax.url.mvn
JBossFuse:karaf@root> config:proplist
config:edit
命令将 config
:edit 命令的重点切换到属于 org.ops4j.pax.url.mvn
persistent ID 的属性。config:proplist
命令输出当前持久性 ID 的所有属性设置。对于 org.ops4j.pax.url.mvn
,您应该会看到类似如下的列表:
org.ops4j.pax.url.mvn.defaultRepositories = file:/path/to/JBossFuse/jboss-fuse-7.12.0.fuse-7_12_0-00019-redhat-00001/system@snapshots@id=karaf.system,file:/home/userid/.m2/repository@snapshots@id=local,file:/path/to/JBossFuse/jboss-fuse-7.12.0.fuse-7_12_0-00019-redhat-00001/local-repo@snapshots@id=karaf.local-repo,file:/path/to/JBossFuse/jboss-fuse-7.12.0.fuse-7_12_0-00019-redhat-00001/system@snapshots@id=child.karaf.system org.ops4j.pax.url.mvn.globalChecksumPolicy = warn org.ops4j.pax.url.mvn.globalUpdatePolicy = daily org.ops4j.pax.url.mvn.localRepository = /path/to/JBossFuse/jboss-fuse-7.12.0.fuse-7_12_0-00019-redhat-00001/data/repository org.ops4j.pax.url.mvn.repositories = http://repo1.maven.org/maven2@id=maven.central.repo, https://maven.repository.redhat.com/ga@id=redhat.ga.repo, https://maven.repository.redhat.com/earlyaccess/all@id=redhat.ea.repo, https://repository.jboss.org/nexus/content/groups/ea@id=fuseearlyaccess org.ops4j.pax.url.mvn.settings = /path/to/jboss-fuse-7.12.0.fuse-7_12_0-00019-redhat-00001/etc/maven-settings.xml org.ops4j.pax.url.mvn.useFallbackRepositories = false service.pid = org.ops4j.pax.url.mvn
org.ops4j.pax.url.mvn.defaultRepositories = file:/path/to/JBossFuse/jboss-fuse-7.12.0.fuse-7_12_0-00019-redhat-00001/system@snapshots@id=karaf.system,file:/home/userid/.m2/repository@snapshots@id=local,file:/path/to/JBossFuse/jboss-fuse-7.12.0.fuse-7_12_0-00019-redhat-00001/local-repo@snapshots@id=karaf.local-repo,file:/path/to/JBossFuse/jboss-fuse-7.12.0.fuse-7_12_0-00019-redhat-00001/system@snapshots@id=child.karaf.system
org.ops4j.pax.url.mvn.globalChecksumPolicy = warn
org.ops4j.pax.url.mvn.globalUpdatePolicy = daily
org.ops4j.pax.url.mvn.localRepository = /path/to/JBossFuse/jboss-fuse-7.12.0.fuse-7_12_0-00019-redhat-00001/data/repository
org.ops4j.pax.url.mvn.repositories = http://repo1.maven.org/maven2@id=maven.central.repo, https://maven.repository.redhat.com/ga@id=redhat.ga.repo, https://maven.repository.redhat.com/earlyaccess/all@id=redhat.ea.repo, https://repository.jboss.org/nexus/content/groups/ea@id=fuseearlyaccess
org.ops4j.pax.url.mvn.settings = /path/to/jboss-fuse-7.12.0.fuse-7_12_0-00019-redhat-00001/etc/maven-settings.xml
org.ops4j.pax.url.mvn.useFallbackRepositories = false
service.pid = org.ops4j.pax.url.mvn
其中 localRepository
设置显示处理器当前使用的本地存储库位置,而 存储库
设置则显示处理程序当前使用的远程存储库列表。
15.3.7. 编辑配置文件
要自定义 Mvn URL 处理程序的属性设置,请编辑以下配置文件:
InstallDir/etc/org.ops4j.pax.url.mvn.cfg
InstallDir/etc/org.ops4j.pax.url.mvn.cfg
此文件中的设置允许您指定本地 Maven 存储库的位置、删除 Maven 存储库、Maven 代理服务器设置等。有关这些设置的详情,请查看配置文件中的注释。
15.3.8. 自定义本地存储库的位置
特别是,如果您的本地 Maven 存储库位于非默认位置,您可以明确配置它,以便访问您本地构建的 Maven 工件。在 org.ops4j.pax.url.mvn.cfg
配置文件中,取消注释 org.ops4j.pax.url.mvn.localRepository
属性,并将其设置为本地 Maven 存储库的位置。例如:
Path to the local maven repository which is used to avoid downloading artifacts when they already exist locally. The value of this property will be extracted from the settings.xml file above, or defaulted to: System.getProperty( "user.home" ) + "/.m2/repository"
# Path to the local maven repository which is used to avoid downloading
# artifacts when they already exist locally.
# The value of this property will be extracted from the settings.xml file
# above, or defaulted to:
# System.getProperty( "user.home" ) + "/.m2/repository"
#
org.ops4j.pax.url.mvn.localRepository=file:E:/Data/.m2/repository
15.3.9. 参考
有关 mvn
URL 语法的详情,请查看原始 Pax URL Mvn 协议 文档。