Question

I just installed Nexus 2.7.1 on my Windows Tomcat and have it up and running. I am trying to deploy a SNAPSHOT jar to the Nexus snapshot repo using the "maven deploy" command but getting following error. Using Maven version 3.0.5. Please guide.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project release-plugin-rnd: Failed to deploy artifacts: Could not transfer artifact com.s tudy:release-plugin-rnd:jar:1.3-20140218.193240-1 from/to snapshots (http://my-nexus-server.com:9090/nexus/content/repositories/snapshots): Failed to transfer file: http://my-nexus-server.com:9090/nexus/content/repos itories/snapshots/com/study/release-plugin-rnd/1.3-SNAPSHOT/release-plugin-rnd-1.3-20140218.193240-1.jar. *Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]*

My settings.xml and pom.xml are mentioned below.

settings.xml

<settings>
    <mirrors>
        <mirror>
            <id>Nexus</id>
            <name>Nexus Public Mirror</name>
            <url>http://localhost:9090/nexus/content/groups/public</url>
            <mirrorOf>central</mirrorOf>
        </mirror>
    </mirrors>
    <servers>
        <server>
            <id>nexus-server</id>
            <username>admin</username>
            <password>admin123</password>
        </server>
    </servers>
</settings>

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.study</groupId>
    <artifactId>release-plugin-rnd</artifactId>
    <version>1.3-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>release-plugin-rnd</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <scm>
        <connection>scm:svn:https://my-svn-server/svn/maven-rnd/release-plugin-rnd/trunk</connection>
        <developerConnection>scm:svn:https://my-svn-server/svn/maven-rnd/release-plugin-rnd/trunk</developerConnection>
        <url>https://my-svn-server/svn/maven-rnd/release-plugin-rnd/trunk</url>
    </scm> 

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <configuration>
                    <tagBase>https://my-svn-server/svn/maven-rnd/release-plugin-rnd/tags</tagBase>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.7</version>
                <executions>
                    <execution>
                        <id>default-deploy</id>
                        <phase>deploy</phase>
                        <goals>
                            <goal>deploy</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <distributionManagement>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Internal Snapshots</name>
            <url>http://my-nexus-server:9090/nexus/content/repositories/snapshots</url>
        </snapshotRepository>
        <repository>
            <id>releases</id>
            <name>Internal Releases</name>
            <url>http://my-nexus-server:9090/nexus/content/repositories/releases</url>
        </repository>
    </distributionManagement>

</project>
Was it helpful?

Solution

I don't have any experience with the mirrors functionality, but I can try to help from when I set up our private company nexus server. When you specify an id in your pom it should match the same id that you defined in your settings.xml. So what you want to do is something like this:

  <servers>
        <server>
            <id>terraframe-releases</id>
            <username>myUsername</username>
            <password>myPassword</password>
        </server>
        <server>
            <id>terraframe-snapshots</id>
            <username>myUsername</username>
            <password>myPassword</password>
        </server>
        <server>
            <id>terraframe-thirdparty</id>
            <username>myUsername</username>
            <password>myPassword</password>
        </server>
    </servers>

In your pom you then reference those same ids:

 <distributionManagement>
    <repository>
      <id>terraframe-releases</id>
      <name>terraframe-releases</name>
      <url>http://terraframe.com:8081/nexus/content/repositories/releases/</url>
      <layout>default</layout>
    </repository>
    <snapshotRepository>
      <id>terraframe-snapshots</id>
      <name>terraframe-snapshots</name>
      <url>http://terraframe.com:8081/nexus/content/repositories/snapshots/</url>
      <layout>default</layout>
    </snapshotRepository>
  </distributionManagement>

In addition, if you're on your own local network (behind a router for example) and the url http://my-nexus-server:9090 is being hosting internally (on a localhost or 192.168. address) you more than likely won't be able to hit that local server with the external domain name http://my-nexus-server:9090 so make sure you specify it with localhost everywhere it asks for it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top