Create local maven repository

社会主义新天地 提交于 2019-11-26 19:17:15

问题


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?


回答1:


You can't create a private repository that way. Check out this article: http://www.theserverside.com/news/1364121/Setting-Up-a-Maven-Repository.

I'm using Artifactory Open Source version.




回答2:


I have to object Stanley, it should work this way. While the article Stanley links leads to way more powerful setups, if you need just a very basic simple repository, then just an Apache with the default configuration can do to provide a 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

The key is that you need the correct folder structure and while the docs don't mention it so explicitly... It is the same structure as a local repository.

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

Assuming that the document root for example.com on your Apache is /var/www/html/ that would cause "YOUR_JAR.jar" to be available for maven on a repository configured with <url>http://example.com/mavenRepository</url>




回答3:


A different way is to include your jar into your local maven repository.

See here for a simple example.




回答4:


Yes you can! For a simple repository that only publish/retrieve artifacts, you can use nginx.

  1. Make sure nginx has http dav module enabled, it should, but nonetheless verify it.

  2. Configure nginx http dav module:

    In Windows: d:\servers\nginx\nginx.conf

    location / {
        # maven repository
        dav_methods  PUT DELETE MKCOL COPY MOVE;
        create_full_put_path  on;
        dav_access  user:rw group:rw all:r;
    }
    

    In Linux (Ubuntu): /etc/nginx/sites-available/default

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            # try_files $uri $uri/ =404;  # IMPORTANT comment this
            dav_methods  PUT DELETE MKCOL COPY MOVE;
            create_full_put_path  on;
            dav_access  user:rw group:rw all:r;
    }
    

    Don't forget to give permissions to the directory where the repo will be located:

    sudo chmod +777 /var/www/html/repository

  3. In your project's pom.xml add the respective configuration:

    Retrieve artifacts:

    <repositories>
        <repository>
            <id>repository</id>
            <url>http://<your.ip.or.hostname>/repository</url>
        </repository>
    </repositories>
    

    Publish artifacts:

    <build>
        <extensions>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-http</artifactId>
                <version>3.2.0</version>
            </extension>
        </extensions>
    </build>
    <distributionManagement>
        <repository>
            <id>repository</id>
            <url>http://<your.ip.or.hostname>/repository</url>
        </repository>
    </distributionManagement>
    
  4. To publish artifacts use mvn deploy. To retrieve artifacts, maven will do it automatically.

And there you have it a simple maven repo.




回答5:


If maven is not creating Local Repository i.e .m2/repository folder then try below step.

In your Eclipse\Spring Tool Suite, Go to Window->preferences-> maven->user settings-> click on Restore Defaults-> Apply->Apply and close



来源:https://stackoverflow.com/questions/13834141/create-local-maven-repository

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