Create local maven repository

后端 未结 3 1334
Happy的楠姐
Happy的楠姐 2020-12-04 16:34

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 s
相关标签:
3条回答
  • 2020-12-04 16:50

    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

    0 讨论(0)
  • 2020-12-04 16:52

    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>.

    0 讨论(0)
  • 2020-12-04 17:00

    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.

    0 讨论(0)
提交回复
热议问题