Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access a Maven repository located in https

I have a Maven project that requires some dependencies that are in a repository located behind HTTPS. I can access the URL by my browser (Firefox) as it asks me a username/password, but in Maven I get Access denied.

Where can I set the username and password so that Maven can use it for that repository? This page deals with certificates and keystores, but I don't have anything like that. Do I need to know where does Firefox stores the certificate for the URL I visited?

like image 556
Luciano Avatar asked Oct 11 '11 02:10

Luciano


People also ask

How do I access my Maven repository?

1) Just run command mvn --version . Go to maven installation directory and view the content of settings. xml file under conf folder. It should tell you which maven central repository is being used.

Does Maven use https?

The natural continuation of this journey begins next month on January 15th, 2020 when we will begin to enforce the use of HTTPS for all consumers of content from Maven Central.

How do I change from HTTP to https in Maven?

The solution is very easy, you just need to replace the urls to maven central repository (and maybe other main repositories) to https instead of http. That's all!!! In case, you have never defined the repositories url and you are using the default values, you just need to add the new repositories with https.

Where is Maven repository url?

By default, Maven will always look in the official Maven repository, which is http://repo1.maven.org. When Maven tries to build a project, it will look in your local repository (by default ~/. m2/repository but you can configure it by changing the <localRepository> value in your ~/. m2/settings.


1 Answers

Username and password is stored into your .m2/ folder in a file called settings.xml (create it if you don't have it).

<settings>
    <servers>
        <server>
            <!-- this id should match the id of the repo server in pom.xml -->
            <id>myrepo</id>
            <username>deployment</username>
            <password>password</password>
        </server>
   </servers>
</settings>

For the second question, it's actually explained in the link you provided, except the keytool link is not working. If I remember right it was posted by a Sun employee in his blog and when Oracle took over the page disappeared. There should be multiple copies of it around the net. One of them is my slightly modified version on GitHub:

https://github.com/stivlo/obliquid-lib/blob/master/src/main/java/org/obliquid/scripts/InstallCert.java

The basic concept is that you don't have to find where Firefox stores the certificates, you download it with the tool in a file.

like image 198
stivlo Avatar answered Nov 15 '22 07:11

stivlo