1

I have a project with the following layout:

enter image description here

My goal was to have mvn looking in the project lib dir as an additional location for potential libs that would not be found in maven repository like j-text-utils.jar for example. So I added this in the pom.xml

 <repositories>
     <repository>
        <id>lib</id>
        <url>file://${project.basedir}/lib</url>
     </repository>
 </repositories>

I took the idea from here: http://randomizedsort.blogspot.co.il/2011/10/configuring-maven-to-use-local-library.html

When running mvn compile, it fails to find the relevant libs in the project folder.

Is there anything wrong with the above?

Thx

isaac.hazan
  • 3,772
  • 6
  • 46
  • 76
  • Install all files from your lib folder into a repository manager which are not available from Central or other repos and use them from there. That's better. For example guava is available from Maven central so you don't need to install them manually just use Maven central. Apart from that you can use the repository at [google to use j-text-utils](http://code.google.com/p/j-text-utils/) which would make the handling simpler. – khmarbaise Feb 18 '14 at 22:18

2 Answers2

1

There is nothing wrong to setup a file based repository. But first and foremost, your directory structure needs to conform to the groupid/artifactid. You should use

set localrepopath=C:\path_to_repo_rootdir
call mvn install:install-file -Dfile=xyz-1.2.jar -DgroupId=com.foo -DartifactId=xyz -Dversion=1.2 -Dpackaging=jar -DlocalRepositoryPath=%localrepopath% -DcreateChecksum=true

It will create directory com\foo\1.2 with all the pom.xml, jar files, checksum files under it.

Then you need to define the dependency for these newly installed artifacts in your own project pom.xml.

If you do not want to setup local repository and only want to add them to the compile classpath, you can consider using "system" scope dependency, but it will make your build not portable and is discouraged in general.

Lan
  • 6,470
  • 3
  • 26
  • 37
  • I already have a repository used by mvn located at c:\Users\\.m2\repository\ . Will this override the other repository or they will live together. At the concept level what i am trying to achieve is using regular mvn repository for commons jar, and a project repository for particular jars that i do not want in the mvn general repository. – isaac.hazan Feb 18 '14 at 15:17
  • The one under the .m2 folder is your local repository cache. You can delete it and once you run the maven project again, all artifacts will be downloaded again from the central repository+ your own repository and store under the .m2 folder – Lan Feb 18 '14 at 15:27
  • Using system scope subtly makes other things break. Having a "starting on project"-script which runs mvn install on each jar file allows Maven to work as expected. – Thorbjørn Ravn Andersen May 02 '17 at 11:50
0

You can do that (just configure the maven-dependency-plugin properly), but I wouldn't suggest that.

There might be a few drawbacks with that direction (e.g., having the Jars there could get into the repository you're using, for many projects it's better to have only one Jar in a dedicated place of your HDD rather than having one of them in each and every project, etc.).

Community
  • 1
  • 1
rlegendi
  • 10,466
  • 3
  • 38
  • 50
  • Unless i misunderstand the suggestion, i am not trying to copy dependencies into my project folder. I want mvn to look into my //${project.basedir}/lib as one of the possible repositories for dependencies when compiling the application. – isaac.hazan Feb 18 '14 at 15:23
  • Oh ok! Then you have to install it to the local repo as @Lan suggested with `mvn install:install`. – rlegendi Feb 18 '14 at 15:29