I want to create local maven repository. I did the following steps:
- Installed maven plugin in eclipse
- Created one folder localrepository in apache server which is accessible using http://< my-domain>/localrepository
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?
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.
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>
A different way is to include your jar into your local maven repository.
See here for a simple example.
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
Yes you can! For a simple repository that only publish/retrieve artifacts, you can use nginx.
Make sure nginx has http dav module enabled, it should, but nonetheless verify it.
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
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>
To publish artifacts use mvn deploy
. To retrieve artifacts, maven will do it automatically.
And there you have it a simple maven repo.