要引入外部的包,最好是将这些外部包发布到仓库,以Maven的方式来管理这些外部包
发布到本地仓库的方法如下:
- mvn install:install-file -Dfile=外部包的路径 \
- -DgroupId=外部包的groupId \
- -DartifactId=外部包的artifactId \
- -Dversion=外部包的版本号 \
- -Dpackaging=jar
- -DgeneratePom=true
- -DcreateChecksum=true
你需要为每个将发布到仓库的外部包指定groupId, artifactId, version。然后,在你的pom.xml中添加这些外部包作为项目的依赖:
- <dependencies>
- <dependency>
- <groupId>外部包1的groupId</groupId>
- <artifactId>外部包1的artifactId</artifactId>
- <version>外部包1的版本号</version>
- </dependency>
- <dependency>
- <groupId>外部包2的groupId</groupId>
- <artifactId>外部包2的artifactId</artifactId>
- <version>外部包2的版本号</version>
- </dependency>
- <!-- 这里加入剩下的外部包 -->
- </dependencies>
注意,上面的install-file命令只会将外部包发布到你的本地仓库,如果你的项目是由多人共享,那么他们需要同样的操作,或者将外部包发布到内部公共仓库。
发布到内部公共仓库后,需要在pom.xml中指定仓库地址:
- <repositories>
- <repository>
- <id>yourcompany</id>
- <url>http://your_shared_maven_repository_url</url>
- </repository>
- </repositories>
2010年2月04日 16:28