Create local maven repository

pbhle picture pbhle · Dec 12, 2012 · Viewed 137.7k times · Source

I want to create local maven repository. I did the following steps:

  1. Installed maven plugin in eclipse
  2. Created one folder localrepository in apache server which is accessible using http://< my-domain>/localrepository
  3. In my project pom.xml I have provided

    <repositories>
        <repository>
            <id>repository</id>
            <url>http://<my-domain>/localMavenRepository</url>
        </repository>
    </repositories>
    

But it is not resolving the jars which are on http://< my-domain>/localMavenRepository

Is there any need to provide repository?

Answer

yankee picture yankee · Mar 25, 2015

Set up a simple repository using a web server with its default configuration. The key is the directory structure. The documentation does not mention it explicitly, but it is the same structure as a local repository.

To set up an internal repository just requires that you have a place to put it, and then start copying required artifacts there using the same layout as in a remote repository such as repo.maven.apache.org. Source

Add a file to your repository like this:

mvn install:install-file \
  -Dfile=YOUR_JAR.jar -DgroupId=YOUR_GROUP_ID 
  -DartifactId=YOUR_ARTIFACT_ID -Dversion=YOUR_VERSION \
  -Dpackaging=jar \
  -DlocalRepositoryPath=/var/www/html/mavenRepository

If your domain is example.com and the root directory of the web server is located at /var/www/html/, then maven can find "YOUR_JAR.jar" if configured with <url>http://example.com/mavenRepository</url>.