gpt4 book ai didi

java - 无法运行使用 Java 10 从 Spring Initializer 创建的基于 Maven 的 Spring 项目

转载 作者:太空宇宙 更新时间:2023-11-04 10:28:39 25 4
gpt4 key购买 nike

我使用 Ubuntu 18.04 ,将 Java 更新到最新版本 10,现在无法运行简单的 Maven 项目。

从 Spring Initializer 创建了一个简单的 Maven 项目并尝试运行它。

以下是控制台中的错误

[ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'parent.relativePath' of POM com.mynotes.spring-cloud:spring-cloud-contract-consumer:0.0.1-SNAPSHOT (/home/dhananjay/Github/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml) points at com.mynotes.spring-cloud:spring-cloud-contract instead of org.springframework.boot:spring-boot-starter-parent, please verify your project structure @ line 14, column 10
[FATAL] Non-resolvable parent POM for com.mynotes.spring-cloud:spring-cloud-contract-consumer:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.13.RELEASE from/to central (https://repo.maven.apache.org/maven2): java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty and 'parent.relativePath' points at wrong local POM @ line 14, column 10
@
[ERROR] The build could not read 1 project -> [Help 1]
org.apache.maven.project.ProjectBuildingException: Some problems were encountered while processing the POMs:
[WARNING] 'parent.relativePath' of POM com.mynotes.spring-cloud:spring-cloud-contract-consumer:0.0.1-SNAPSHOT (/home/dhananjay/Github/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml) points at com.mynotes.spring-cloud:spring-cloud-contract instead of org.springframework.boot:spring-boot-starter-parent, please verify your project structure @ line 14, column 10
[FATAL] Non-resolvable parent POM for com.mynotes.spring-cloud:spring-cloud-contract-consumer:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.13.RELEASE from/to central (https://repo.maven.apache.org/maven2): java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty and 'parent.relativePath' points at wrong local POM @ line 14, column 10

at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:382)
at org.apache.maven.graph.DefaultGraphBuilder.collectProjects (DefaultGraphBuilder.java:400)
at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor (DefaultGraphBuilder.java:391)
at org.apache.maven.graph.DefaultGraphBuilder.build (DefaultGraphBuilder.java:78)
at org.apache.maven.DefaultMaven.buildGraph (DefaultMaven.java:511)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:221)
at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:194)
at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:107)
at org.apache.maven.cli.MavenCli.execute (MavenCli.java:955)
at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290)
at org.apache.maven.cli.MavenCli.main (MavenCli.java:194)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke (Method.java:564)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356)
[ERROR]
[ERROR] The project com.mynotes.spring-cloud:spring-cloud-contract-consumer:0.0.1-SNAPSHOT (/home/dhananjay/Github/spring-cloud-contract/spring-cloud-contract-consumer/pom.xml) has 1 error
[ERROR] Non-resolvable parent POM for com.mynotes.spring-cloud:spring-cloud-contract-consumer:0.0.1-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.13.RELEASE from/to central (https://repo.maven.apache.org/maven2): java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty and 'parent.relativePath' points at wrong local POM @ line 14, column 10 -> [Help 2]
org.apache.maven.model.resolution.UnresolvableModelException: Could not transfer artifact org.springframework.boot:spring-boot-starter-parent:pom:1.5.13.RELEASE from/to central (https://repo.maven.apache.org/maven2): java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
at org.apache.maven.project.ProjectModelResolver.resolveModel (ProjectModelResolver.java:197)
at org.apache.maven.project.ProjectModelResolver.resolveModel (ProjectModelResolver.java:243)
at org.apache.maven.model.building.DefaultModelBuilder.readParentExternally (DefaultModelBuilder.java:1051)
at org.apache.maven.model.building.DefaultModelBuilder.readParent (DefaultModelBuilder.java:829)
at org.apache.maven.model.building.DefaultModelBuilder.build (DefaultModelBuilder.java:331)
at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:429)
at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:398)
at org.apache.maven.project.DefaultProjectBuilder.build (DefaultProjectBuilder.java:362)
at org.apache.maven.graph.DefaultGraphBuilder.collectProjects (DefaultGraphBuilder.java:400)
at org.apache.maven.graph.DefaultGraphBuilder.getProjectsForMavenReactor (DefaultGraphBuilder.java:391)
at org.apache.maven.graph.DefaultGraphBuilder.build (Defaul

我在许多项目中都遇到过类似的错误

Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

谷歌搜索了一下,发现了这个修复。 https://gist.github.com/mikaelhg/527204e746984cf9a33f7910bb8b4cb6这适用于简单的 Maven 项目,但不适用于 Spring 相关项目。

如有任何帮助,我们将不胜感激。

恢复到 java 8,一切正常,但我想知道为什么它不适用于 java 10。

$ sudo update-alternatives --config javac
There are 2 choices for the alternative javac (providing /usr/bin/javac).

Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/bin/javac 1081 auto mode
1 /usr/lib/jvm/java-10-oracle/bin/javac 2 manual mode
* 2 /usr/lib/jvm/java-8-oracle/bin/javac 1081 manual mode

Press <enter> to keep the current choice[*], or type selection number:

$ sudo update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 auto mode
1 /usr/lib/jvm/java-10-oracle/bin/java 2 manual mode
* 2 /usr/lib/jvm/java-8-oracle/jre/bin/java 1081 manual mode

Press <enter> to keep the current choice[*], or type selection number:
<小时/>
$ java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

$ javac -version
javac 1.8.0_171

POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.mynotes.spring-cloud</groupId>
<artifactId>spring-cloud-contract-producer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>spring-cloud-contract-producer</name>
<description>Demo project for Spring Boot</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Edgware.SR3</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-verifier</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>


</project>

最佳答案

我们在工作时的电脑上遇到了这个问题。原来是一个搞砸的java版本。我们安装了 java 8 oracle 而不是 openjdk-8。

删除所有 Java 安装并从头开始,并确保安装 openjdk 而不是 Oracle 的

对于卸载 java,我将向您推荐此线程 - https://askubuntu.com/questions/84483/how-to-completely-uninstall-java

安装:

sudo apt-get install openjdk-8-jdk

关于java - 无法运行使用 Java 10 从 Spring Initializer 创建的基于 Maven 的 Spring 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50308685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com