2017-03-08 34 views
0

我创建了一个Maven原型并上传到了Nexus存储库。我可以在Windows上使用“mvn archetype:generate -DarchetypeCatalog = http://myhost:8080/nexus/content/repositories/my-snapshots/archetype-catalog.xml”命令生成一个基于该原型的项目。目录xml是有效的,我可以手动从浏览器打开。远程http archetypeCatalog在Linux中不起作用

现在我在Linux上遵循相同的步骤,在conf/setting.xml中将服务器部分和存储库配置文件配置为与Windows相同的内容。 maven报告“没有目录定义,使用内部目录”。看来Maven没有阅读“-DarchetypeCatalog = ....”部分。

调试日志如下。 Maven版本是3.3.9。这个问题在Redhat和Ubuntu上都有转载。希望任何人都能提出解决方案。谢谢。

[DEBUG] RuntimeInstance successfully initialized. 
[DEBUG] Configuring mojo 'org.apache.maven.plugins:maven-archetype-plugin:3.0.0:generate' with basic configurator --> 
[DEBUG] (f) archetypeCatalog = http://myhost:8080/nexus/content/repositories/my-snapshots/archetype-catalog.xml 
[DEBUG] (f) basedir = /opt/testmaven 
[DEBUG] (f) interactiveMode = true 
[DEBUG] (f) localRepository =  id: local 
     url: file:///root/.m2/repository/ 
    layout: default 
snapshots: [enabled => true, update => always] 
releases: [enabled => true, update => always] 

[DEBUG] (f) remoteArtifactRepositories = [  id: my-snapshots 
     url: http://myhost:8080/nexus/content/repositories/my-snapshots 
    layout: default 
snapshots: [enabled => true, update => always] 
releases: [enabled => false, update => always] 
,  id: central 
     url: https://repo.maven.apache.org/maven2 
    layout: default 
snapshots: [enabled => false, update => daily] 
releases: [enabled => true, update => daily] 
] 
[DEBUG] (f) session = [email protected] 
[DEBUG] -- end configuration -- 
[INFO] Generating project in Interactive mode 
[INFO] No catalog defined. Using internal catalog 
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.archetypes:maven-archetype-quickstart:1.0) 
Choose archetype: 
1: internal -> org.apache.maven.archetypes:maven-archetype-archetype (An archetype which contains a sample archetype.) 
....... 

回答

0

Settings.XML中,我们需要配置镜像:

<mirrors> 
    <mirror> 
    <name>Local Nexus Mirror</name> 
    <id>nexus</id> 
    <mirrorOf>*</mirrorOf> 
    <url>http://myhost:8080/nexus/content/groups/public</url> 
    </mirror> 
</mirrors> 

一旦你配置的Nexus是所有仓库镜子,Maven的现在咨询的Nexus的本地安装而不是去中央Maven仓库。

如果Nexus有要求的工件,工件将从本地的Nexus安装中提供。

我们可以尝试指定-DarchetypeCatalog=remote-DarchetypeCatalog=local,同时通过mvn archetype:generate生成maven工件。

如果原型cataog在本地可用,我们可以直接使用-Dcatalog=<url>