配置Maven使用本地lib文件夹
2015-11-23 11:45
155 查看
The official "Maven Way" of dependency management is to use Maven Central and local repository specified in thesettings.xml file (which usually points to$HOME/.m2/repository. While it works great for projects that rely on a large number of
open source libraries and satisfies 95% of dependency management needs in those projects, there is that 5% of the time when a jar isnot sourced from a Maven project. One example is a jar using JNI so is only available for certain OS platforms. How
do we integrate this jar into Maven dependency management? If you search the web for hints, you may be led to believe that you either have to bend to the Maven Way or to use the systemPath. But the Maven Way will force you to maintain a local repository for
a trival library. The systemPath on the other hand does not work naturally with packaging. Developers will most likely ask "Can I check in this library to my (your_favorite_VCS) with my project and still have Maven use it in a way just like any other dependency?"
The answer is YES. Just follow the steps below:
1. Create a directory under your project, say "lib".
2. Use Maven to install your jar to the lib directory.
mvn install:install-file -DgroupId=com.baidu -DartifactId=bccs-api-lib -Dversion=2.0.1 -Dpackaging=jar -Dfile=bccs-api-lib-2.0.1.jar -DlocalRepositoryPath=D:\svn\go_backend\lib
[b]3. Setup your POM like this.[/b]
[b] <repositories>
<repository>
<!-- DO NOT set id to "local" because it is reserved by Maven -->
<id>lib</id>
<url>file://${project.basedir}/lib</url>
</repository>
</repositories>[/b]
[b] <dependencies>
<dependency>
<groupId>com.baidu</groupId>
<artifactId>bccs-api-lib</artifactId>
<version>2.0.1</version>
</dependency>[/b]
[b] ...
[/b]
Now you can check in/out [b]bccs-api-lib-2.0.1.jar just like any other file in your project and Maven will manage the dependency on mylib.jar just like any other dependency artifact. Perfect harmony. :-)
[/b]
open source libraries and satisfies 95% of dependency management needs in those projects, there is that 5% of the time when a jar isnot sourced from a Maven project. One example is a jar using JNI so is only available for certain OS platforms. How
do we integrate this jar into Maven dependency management? If you search the web for hints, you may be led to believe that you either have to bend to the Maven Way or to use the systemPath. But the Maven Way will force you to maintain a local repository for
a trival library. The systemPath on the other hand does not work naturally with packaging. Developers will most likely ask "Can I check in this library to my (your_favorite_VCS) with my project and still have Maven use it in a way just like any other dependency?"
The answer is YES. Just follow the steps below:
1. Create a directory under your project, say "lib".
2. Use Maven to install your jar to the lib directory.
mvn install:install-file -DgroupId=com.baidu -DartifactId=bccs-api-lib -Dversion=2.0.1 -Dpackaging=jar -Dfile=bccs-api-lib-2.0.1.jar -DlocalRepositoryPath=D:\svn\go_backend\lib
[b]3. Setup your POM like this.[/b]
[b] <repositories>
<repository>
<!-- DO NOT set id to "local" because it is reserved by Maven -->
<id>lib</id>
<url>file://${project.basedir}/lib</url>
</repository>
</repositories>[/b]
[b] <dependencies>
<dependency>
<groupId>com.baidu</groupId>
<artifactId>bccs-api-lib</artifactId>
<version>2.0.1</version>
</dependency>[/b]
[b] ...
[/b]
Now you can check in/out [b]bccs-api-lib-2.0.1.jar just like any other file in your project and Maven will manage the dependency on mylib.jar just like any other dependency artifact. Perfect harmony. :-)
[/b]
相关文章推荐
- ACE内存管理之ACE_Cached_Allocator类详解
- lua绑定c++的时候常见得错误
- android activity监听加载完毕事件
- Android编程设置全屏的方法实例详解
- 软件设计文档
- Android完美解决The specified child already has a parent. You must call removeView() on the child
- C#调用endtask
- Xcode7.1.1更新内容
- linux shell date 时间运算以及时间差计算方法
- 泊松分布和指数分布:10分钟教程
- 字符串转换JSON
- Mysql优化
- jQuery弹出层插件大全
- 断点续传和下载原理分析[转]
- Linux目录操作命令
- c#查找窗口的两种办法
- 谁可以说出HashMap和HashSet的相同点和不同点。
- UDP通信
- XEN虚拟机在Linux上的安装和使用教程
- 蒙特卡罗方法入门