10

I am working on a java project currently, my problem is a bit weird as yesterday my code was working fine then suddenly today when I try to build and test my code I get this error:

Failed to execute goal on project extraportGlobalSearch: Could not resolve dependencies for project com.api:extraportGlobalSearch:jar:1.0: Failed to collect dependencies for [org.glassfish.jersey.containers:jersey-container-grizzly2-http:jar:2.27 (compile), org.glassfish.jersey.inject:jersey-hk2:jar:2.27 (compile), junit:junit:jar:4.9 (test), com.googlecode.json-simple:json-simple:jar:1.1.1 (compile), com.fasterxml.jackson.core:jackson-annotations:jar:2.5.4 (compile), javax.servlet:javax.servlet-api:jar:3.0.1 (compile), com.google.zxing:core:jar:3.3.3 (compile), com.fasterxml.jackson.core:jackson-databind:jar:2.5.4 (compile), oracle:ojdbc:jar:11.2.0.4 (compile), org.glassfish.grizzly:grizzly-http-server:jar:2.4.0 (compile)]: Failed to read artifact descriptor for oracle:ojdbc:jar:11.2.0.4: Could not transfer artifact oracle:ojdbc:pom:11.2.0.4 from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/oracle/ojdbc/11.2.0.4/ojdbc-11.2.0.4.pom. Return code is: 501 , ReasonPhrase:HTTPS Required. -> [Help 1]

To see the full stack trace of the errors, re-run Maven with the -e switch.
Re-run Maven using the -X switch to enable full debug logging.

For more information about the errors and possible solutions, please read the following articles:
[Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

I tried to add another repo using https://repo.maven.apache.org/maven2/ url in my pom.xml but the error still persist. I have tried to resolve this for the past 5 hours, it would be great if anyone can help me, here is my pom.xml:

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

    <modelVersion>4.0.0</modelVersion>

    <groupId>com.api </groupId>
    <artifactId>extraportGlobalSearch</artifactId>
    <packaging>jar</packaging>
    <version>1.0</version>
    <name>extraportGlobalSearch</name>

    <repositories>
      <repository>
        <id>apache2-https</id>
        <name>Apache 2 https</name>
        <url>https://repo.maven.apache.org/maven2/</url>
      </repository>
    </repositories>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.glassfish.jersey</groupId>
                <artifactId>jersey-bom</artifactId>
                <version>${jersey.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-grizzly2-http</artifactId>
        </dependency>
        <dependency>
            <groupId>org.glassfish.jersey.inject</groupId>
            <artifactId>jersey-hk2</artifactId>
        </dependency>

        <!-- uncomment this to get JSON support:
         <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-binding</artifactId>
        </dependency>-->

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
            <scope>test</scope>
        </dependency>
            <!-- https://mvnrepository.com/artifact/com.googlecode.json-simple/json-simple -->
    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>


        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-annotations</artifactId>
            <version>2.5.4</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>com.google.zxing</groupId>
            <artifactId>core</artifactId>
            <version>3.3.3</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.5.4</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>oracle</groupId>
            <artifactId>ojdbc</artifactId>
            <version>11.2.0.4</version>
            <type>jar</type>
        </dependency>
        <dependency>
            <groupId>org.glassfish.grizzly</groupId>
            <artifactId>grizzly-http-server</artifactId>
            <version>2.4.0</version>
            <type>jar</type>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.4.3</version>
                <executions>
                       <!-- Run shade goal on package phase -->
                    <execution>
                        <phase>package</phase>
                        <goals>
                        <goal>shade</goal> 
                        </goals>

                <configuration>
                    <transformers>
                        <!-- add Main-Class to manifest file -->    
                      <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">             
                    <mainClass>com.api.GlobalSearch.Main</mainClass>
                       </transformer>
                   </transformers>
                </configuration>

              </execution>
           </executions>
            </plugin>
        </plugins>
    </build>

    <properties>
        <jersey.version>2.27</jersey.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

</project>

Help needed. Thanks in advance.

diyana najieha
  • 101
  • 1
  • 1
  • 3
  • 1
    Hi Welcome to StackOverflow! I think that this thread ( https://stackoverflow.com/questions/59763531/maven-dependencies-are-failing-with-501-error) could give you a clue about the root of the issue? Please, could you add your settings.xml specifications to your question? – Jaime S Jan 16 '20 at 09:30

6 Answers6

23
<packaging>jar</packaging>
<pluginRepositories>
    <pluginRepository>
        <id>central</id>
        <name>Central Repository</name>
        <url>https://repo.maven.apache.org/maven2</url>
        <layout>default</layout>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
        <releases>
            <updatePolicy>never</updatePolicy>
        </releases>
    </pluginRepository>
</pluginRepositories>
<repositories>
    <repository>
        <id>central</id>
        <name>Central Repository</name>
        <url>https://repo.maven.apache.org/maven2</url>
        <layout>default</layout>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
  • 2
    This worked for me, I added it after the packaging label on the pom. – Cristhian Pineda Jan 16 '20 at 22:54
  • 1
    I'd say that the answer is not Netbeans related though and manually defining the repository is not needed if using a recent version of maven. The actual problem is how to use a recent version of maven in Netbeans as the default one, on Netbeans 8.2 at least, is outdated. – Arch Feb 14 '20 at 15:08
  • This is great workaround! Worked fine on my NetBeans 8.2. Thanks! – PKey Mar 17 '20 at 11:15
15

The issue is related to maven moving to https only: https://blog.sonatype.com/central-repository-moving-to-https

I have found that my problem was that Netbeans (8.2) was set to use the bundled maven executable (3.0.5). This version of maven is outdated and does not automatically reach for the https repo.

I have a newer version installed (Apache Maven 3.5.4 (Red Hat 3.5.4-5) ) that worked by executing mvn clean install in my project's directory.

To get Netbeans to use a different version of maven you can go to Tools->Options->Java->Maven and in Maven Home point to where your maven installation is located. For me it was /usr/bin/mvn and I had to define the path as just /usr as it seems that Netbeans expects to find a directory named bin containing the mvn executable.

Also, related to maven moving repositories, for certain old dependencies I had to use the now insecure endpoint in my maven config:

        <pluginRepository>
            <id>Codehaus repository</id>
            <url>http://insecure.repo1.maven.org/maven2/</url>
        </pluginRepository> 

Just adding this in case it is useful to anyone.

Arch
  • 507
  • 3
  • 18
3

You should update your maven version, the last maven version use https.

  1. Download maven https://maven.apache.org/download.cgi (binary zip file) and extract it.
  2. In netbeans, go to Tools -> Options -> Java -> Maven. In Maven Home select Browse, and select the folder where you extract maven
  3. Enjoy it!
victorpacheco3107
  • 822
  • 3
  • 10
  • 32
1

While the other responses give you workarounds by manually configuring the repository or a more recent version of Maven, the true source of the problem is that Netbeans (8.2) has became obsolete and is no more updated, you'd better migrate to Apache Netbeans (currently at version 11.3).

jmd
  • 877
  • 8
  • 12
0

I fixed the issue by updating to latest maven version, it started to use https instead of http to download all the deps.

diyana najieha
  • 101
  • 1
  • 1
  • 3
  • Can you share you maven version? I'm on Apache Maven 3.5.4 (Red Hat 3.5.4-5) on Fedora 29 and for one project it correctly fetches from the https url but for another, much more bare bones one it tries to use the http one – Arch Jan 16 '20 at 16:37
  • @Arch I've upgraded to 3.6.3 and I'm still having the issue. – NuAlphaMan Jan 22 '20 at 15:37
  • @NuAlphaMan have you tried the solution I've posted in my answer? – Arch Jan 28 '20 at 11:51
  • 2
    Hi @diyana-najieha, could you please review the answers and mark the one you believe is most relevant? – Arch Feb 04 '20 at 09:54
0

I changed maven version for global netbeans configuration Tools -> Options -> Java ->Maven ->Maven Home and Browse your maven installation of windows system (for example maven3.6) , i think so maven version embed netbeans 8.2 needs updated