Spring Tool Suite Maven 项目在 xsi:schemaLocation 的 pom.xml 中出现错误

问题描述 投票:0回答:4

我刚刚开始我的第一个 Maven 项目,但在 xsi:schemaLocation 部分的 pom.xml 文件的第一行出现错误。

我的 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.example.demo</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Demo Course API</name>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.0.RELEASE</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>
<properties>
    <java.version>1.8</java.version>
</properties>


<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.4.2</version>
        </plugin>
    </plugins>
</build>
</project>

错误描述的前几行是

Failure to transfer com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0 from https://repo.maven.apache.org/maven2 was cached in the 
 local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not 
 transfer artifact com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0 from/to central (https://repo.maven.apache.org/maven2): The operation was 
 cancelled. org.eclipse.aether.transfer.

我刚刚从 spring 入门指南中复制了它,但仍然出现错误。不知道该怎么办。 我的 mvn -v 是 3.5.2

java maven spring-boot
4个回答
1
投票

M2E版本与maven-jar-plugin 3.1.2版本不兼容。

在 M2E 或 maven-jar-plugins 的开发团队解决该问题之前,您必须在 pom.xml 文件中添加以下行才能解决此问题:

</project>
<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.1.1</version>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

0
投票

尝试将此依赖项包含在您的 pom.xml 中并检查:

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>2.9.0.pr2</version>
</dependency>

0
投票

分析错误描述对于解决上述问题有很大帮助。 错误计数为 53。

首先,正如 @Duho 所说,添加 jackson 依赖项有助于减少一些错误,现在错误计数减少到 35。 然后错误出现在 hibernate 验证器依赖项中,我通过添加 hibernate 验证器依赖项修复了这个问题。 可以通过右键项目-->Maven-->添加依赖来添加依赖。

然后发现maven从中央仓库下载了一些不完整的文件到本地仓库,下载不完整。因此,我从 Users/'myName'/.m2/repository 文件夹中删除了所有带有“.lastUpdated”扩展名的文件。

然后通过右键单击-->Maven-->更新项目来更新项目有助于解决所有错误。

它对我有用..希望这对任何有同样问题的人都有效。


0
投票

上述解决方案也有效,但有时不起作用。这是因为你可能包含了mysql-driver、spring-data-jpa,但没有在application.properties中指定数据源、用户名和密码。

您可以删除这些依赖项或配置以上所有内容。就我而言,这是我发现的一个区域。我认为这可能会有所帮助:)。

© www.soinside.com 2019 - 2024. All rights reserved.