Maven localRepository

微笑、不失礼 提交于 2019-12-07 16:25:25

问题


I know that this is not the idea behind Maven but:

I would like to have a local maven repo (.m2) inside the progect directory with a relative path. Is there any way I can have my pom do this? Is there a better alternative?

So, basically what I want is not to be dependent on any exterior repositorys.

Thx for your help :)

PS1 - I'm sort of a java noob (c/c++ here) and a total maven
PS2 - The settings.xml file on maven installation dir/conf has a localRepository element, but I believe I can't have a relative patch there. Additionally this would be not linked to the progect, but to the box where maven is installed.


回答1:


Note that in pom.xml you can set the dependency reference to the location of specific jar file stored in file system, suppose you have a sub-folder lib under project root folder which contains all jar libraries:

<dependency>
  <groupId>commons-logging</groupId>
  <artifactId>commons-logging</artifactId>
  <version>1.0.4</version>
  <scope>system</scope>
  <systemPath>${project.basedir}/lib/commons-logging-1.0.4.jar</systemPath>
</dependency>

By doing this, the groupId, artifactId and version become meaningless. From my own experience, I saw a oracle project before which has many customized jar with others that not available via online maven repository, ugly but doable.




回答2:


I would like to have a local maven repo (.m2) inside the progect directory with a relative path. Is there any way I can have my pom do this?

Yes, there is a way: you can specify path to local repo by specifying in $M2_HOME\conf\setting.xml

But this approach is really not good if you (or other developers) work with more than one project.

Is there a better alternative?

Yes, there is a better alternative:) You can import any jar in you local maven repository so you will not depend on maven central repo and you will not be forced to store local repository inside your project. Check this tiny article How To Include Custom Library Into Maven Local Repository? to learn how to do it.

With this approach you can store all required 3rd party jars in your project as well as a shell/batch script that imports jars to the local repo. And developers will just execute the script to import dependencies to local repo instead of modifying maven settings to use local repo from some specific place (from the project).



来源:https://stackoverflow.com/questions/8841453/maven-localrepository

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!