【问题标题】:Netbeans Maven Failed to execute goal on projectNetbeans Maven未能在项目上执行目标
【发布时间】:2020-05-03 01:20:35
【问题描述】:

我目前正在处理一个 java 项目,我的问题有点奇怪,因为昨天我的代码工作正常,然后今天突然当我尝试构建和测试我的代码时,我收到了这个错误:

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

我尝试在我的 pom.xml 中使用 https://repo.maven.apache.org/maven2/ url 添加另一个 repo,但错误仍然存​​在。在过去的 5 个小时里,我一直在尝试解决这个问题,如果有人能帮助我,那就太好了,这是我的 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>

需要帮助。提前致谢。

【问题讨论】:

  • 您好,欢迎来到 StackOverflow!我认为这个线程(stackoverflow.com/questions/59763531/…)可以为您提供有关问题根源的线索?请问,您能否将您的 settings.xml 规范添加到您的问题中?

标签: java maven http netbeans dependencies


【解决方案1】:
<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>

【讨论】:

  • 这对我有用,我在 pom 的包装标签之后添加了它。
  • 我会说答案与 Netbeans 无关,如果使用最新版本的 maven,则不需要手动定义存储库。实际的问题是如何在 Netbeans 中使用最新版本的 maven 作为默认版本,至少在 Netbeans 8.2 上已经过时了。
  • 这是一个很好的解决方法!在我的 NetBeans 8.2 上运行良好。谢谢!
【解决方案2】:

该问题与仅迁移到 https 的 maven 有关:https://blog.sonatype.com/central-repository-moving-to-https

我发现我的问题是 Netbeans (8.2) 被设置为使用捆绑的 maven 可执行文件 (3.0.5)。此版本的 maven 已过时,不会自动访问 https 存储库。

我安装了更新的版本(Apache Maven 3.5.4 (Red Hat 3.5.4-5) ) 通过在我的项目目录中执行 mvn clean install 来工作。

要让 Netbeans 使用不同版本的 maven,您可以转到 Tools->Options->Java->Maven 并在 Maven Home 中指向您的 maven安装位置。对我来说,它是 /usr/bin/mvn ,我必须将路径定义为 /usr ,因为 Netbeans 似乎希望找到一个名为 bin 的目录 包含 mvn 可执行文件。

此外,与 maven 移动存储库有关,对于某些旧依赖项,我必须在我的 maven 配置中使用现在的 insecure 端点:

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

只是添加这个以防它对任何人有用。

【讨论】:

  • 这很有用,我的 maven 版本已经过时了。非常感谢。
【解决方案3】:

你应该更新你的 maven 版本,最后一个 maven 版本使用 https。

  1. 下载 maven https://maven.apache.org/download.cgi(二进制 zip 文件)并解压。
  2. 在 netbeans 中,转到工具 -> 选项 -> Java -> Maven。在 Maven Home 中选择 Browse,然后选择您提取 maven 的文件夹
  3. 尽情享受吧!

【讨论】:

    【解决方案4】:

    虽然其他回复通过手动配置存储库或更新版本的 Maven 为您提供了解决方法,但问题的真正根源是 Netbeans (8.2) 已过时且不再更新,您最好迁移到Apache Netbeans(当前版本为 11.3)。

    【讨论】:

      【解决方案5】:

      我通过更新到最新的 maven 版本解决了这个问题,它开始使用 https 而不是 http 来下载所有的 deps。

      【讨论】:

      • 你能分享你的maven版本吗?我在 Fedora 29 上的 Apache Maven 3.5.4 (Red Hat 3.5.4-5) 上,对于一个项目,它正确地从 https url 获取,但对于另一个项目,它尝试使用 http 一个更简单的框架跨度>
      • @Arch 我已升级到 3.6.3,但问题仍然存在。
      • @NuAlphaMan 您是否尝试过我在答案中发布的解决方案?
      • 嗨@diyana-najieha,您能否查看答案并标记您认为最相关的答案?
      【解决方案6】:

      我更改了全局 netbeans 配置的 maven 版本工具 -> 选项 -> Java ->Maven ->Maven Home 并浏览您的 Windows 系统的 maven 安装(例如 maven3.6),我认为嵌入 netbeans 8.2 的 maven 版本需要更新

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-09-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-08-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多