要引入外部的包,最好是将这些外部包发布到仓库,以Maven的方式来管理这些外部包

来源:互联网 发布:淘宝扫二维码别人付款 编辑:程序博客网 时间:2024/06/03 20:04

要引入外部的包,最好是将这些外部包发布到仓库,以Maven的方式来管理这些外部包

发布到本地仓库的方法如下:

Shell代码  收藏代码
  1. mvn install:install-file  -Dfile=外部包的路径 \  
  2.                           -DgroupId=外部包的groupId \  
  3.                           -DartifactId=外部包的artifactId \  
  4.                           -Dversion=外部包的版本号 \  
  5.                           -Dpackaging=jar 
  6.                           -DgeneratePom=true
  7.                           -DcreateChecksum=true
具体使用方法请见 http://maven.apache.org/plugins/maven-install-plugin

你需要为每个将发布到仓库的外部包指定groupId, artifactId, version。然后,在你的pom.xml中添加这些外部包作为项目的依赖:
Xml代码  收藏代码
  1. <dependencies>  
  2.   <dependency>  
  3.     <groupId>外部包1的groupId</groupId>  
  4.     <artifactId>外部包1的artifactId</artifactId>  
  5.     <version>外部包1的版本号</version>  
  6.   </dependency>  
  7.   <dependency>  
  8.     <groupId>外部包2的groupId</groupId>  
  9.     <artifactId>外部包2的artifactId</artifactId>  
  10.     <version>外部包2的版本号</version>  
  11.   </dependency>  
  12.   <!-- 这里加入剩下的外部包 -->  
  13. </dependencies>  


注意,上面的install-file命令只会将外部包发布到你的本地仓库,如果你的项目是由多人共享,那么他们需要同样的操作,或者将外部包发布到内部公共仓库。

发布到内部公共仓库后,需要在pom.xml中指定仓库地址:
Xml代码  收藏代码
  1. <repositories>  
  2.   <repository>  
  3.     <id>yourcompany</id>  
  4.     <url>http://your_shared_maven_repository_url</url>  
  5.   </repository>  
  6. </repositories>  
2010年2月04日 16:28
0 0