简体   繁体   English

如何设置和使用内部Maven存储库?

[英]How to setup and use internal Maven repository?

Good day, everyone. 今天是个好日子。

I'm trying to setup an internal repository that I can share with some people within a local network with no access to the Internet. 我正在尝试建立一个内部存储库,可以与局域网中的某些人共享,而无需访问Internet。 So far, I have setup Archiva in my local machine and point the repository to my ~/.m2/repository. 到目前为止,我已经在本地计算机上设置了Archiva,并将存储库指向〜/ .m2 /存储库。 I asked those people to setup their Maven settings.xml and add the following profile: 我请那些人设置他们的Maven settings.xml并添加以下配置文件:

 <profile>
 <id>archiva</id>

 <repositories>
  <repository>
   <id>archiva</id>
   <url>http://mymachine:8087/archiva/repository/internal/</url>
   <releases>
    <enabled>true</enabled>
   </releases>
   <snapshots>
    <enabled>true</enabled>
   </snapshots>
  </repository>
 </repositories>
 <pluginRepositories>
  <pluginRepository>
   <id>archiva</id>
   <url>http://mymachine:8087/archiva/repository/internal/</url>
   <releases>
    <enabled>true</enabled>
   </releases>
   <snapshots>
    <enabled>true</enabled>
   </snapshots>
  </pluginRepository>
 </pluginRepositories>
 </profile>

I've also asked them to set this profile as always active. 我还要求他们将此配置文件设置为始终有效。 However, when they try to generate a new Java project using mvn archetype:generate , they always get an error. 但是,当他们尝试使用mvn archetype:generate新的Java项目时,总是会收到错误消息。 I actually forgot what the error was but it had something to do with the goal. 我实际上忘记了错误所在,但这与目标有关。 They can download the jars from Archiva but the generation still fails. 他们可以从Archiva下载罐子,但是这一代仍然失败。 I also gave them a copy of the archetype catalog but it's still failing. 我还给了他们原型目录的副本,但是仍然失败了。 What am I missing? 我想念什么?

I have setup Archiva in my local machine and point the repository to my ~/.m2/repository 我已经在本地计算机上设置了Archiva,并将存储库指向〜/ .m2 / repository

I think that this is a wrong idea. 我认为这是一个错误的想法。 You mix two concepts together. 您将两个概念混合在一起。 Archiva is a foreign repository, while ~/.m2 is a local repository. Archiva是一个外部存储库,而~/.m2是本地存储库。 They should be kept separately, even if the physical machine is the same. 即使物理计算机相同,也应将它们分开保存。

Are you familiar with archetypes? 您熟悉原型吗? They are project templates, and you need to create an archetype project (and mvn deploy it to your server) so that they can initialize first. 它们是项目模板,您需要创建一个原型项目(并将mvn deploy到您的服务器),以便它们可以首先进行初始化。 Then, they'll pull with code like, 然后,他们将使用诸如

mvn archetype:generate -DarchetypeGroupId=edu.berkeley.cs.sketch -DarchetypeArtifactId=skalch-archetype2 ...

See full example at ntung.com/mvn . 请参阅ntung.com/mvn中的完整示例。 I have an example of an archetype project here (github). 我有一个原型项目的例子在这里 (github上)。 They're pretty basic and easy to read. 它们非常基础,而且易于阅读。 Note that the archetype project is a maven project itself, so the top level pom.xml is for the archetype, and the src/main/resources/archetype-resources/pom.xml is where you want to put your above code referencing your server. 请注意,原型项目本身就是一个Maven项目,因此顶级pom.xml用于原型,而src/main/resources/archetype-resources/pom.xml是您要在上面放置引用服务器代码的位置。

Maybe you mean to type archetype:create instead of archetype:generate ? 也许您的意思是键入archetype:create而不是archetype:generate See http://maven.apache.org/guides/getting-started/index.html#How_do_I_setup_Maven if that's the case. 如果是这种情况,请参见http://maven.apache.org/guides/getting-started/index.html#How_do_I_setup_Maven

BTW, since Maven uses so many plugins, good luck getting it to work without an internet connection! 顺便说一句,由于Maven使用了许多插件,因此如果没有互联网连接就可以运行它了! You might try buildr instead. 您可以尝试使用buildr。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM