Java 为什么我在 pom.xml 的第 1 行收到未知错误?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/56142369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 01:15:03  来源:igfitidea点击:

Why am I getting Unknown error in line 1 of pom.xml?

javamavenspring-bootpom.xml

提问by Shravani

Getting unknown error at Line 1 in pom.xmlin Eclipse IDE. It was working fine till yesterday, but all of a sudden after updating my project from master and after fixing merge conflicts getting "Unknown error" in pom.xml. Except me, none of my teammates are facing this issue. I also changed the workspace, deleted cache but still no luck.

pom.xml在 Eclipse IDE中的第 1 行出现未知错误。直到昨天它都工作正常,但是在从 master 更新我的项目并修复合并冲突后突然在 pom.xml 中出现“未知错误”。除了我,我的队友都没有遇到这个问题。我还更改了工作区,删除了缓存,但仍然没有运气。

I am using the h2 database for this project, in spite of inserting values in data.sql, it is not picking up any values and inserting into h2 DB tables. Before this issue, it was working fine. I feel its due to the issue in pom.xml, I am not sure though. Please help

我在这个项目中使用了 h2 数据库,尽管在 data.sql 中插入了值,但它没有选择任何值并插入到 h2 DB 表中。在此问题之前,它运行良好。我觉得这是由于 pom.xml 中的问题,但我不确定。请帮忙

I deleted the existing project and took the latest code from master. After that deleted .m2 folder under users including the repository folder. I did update project and enabled Forced update of snapshots/releases, maven clean and maven build. But nothing helps.

我删除了现有项目并从 master 那里获取了最新代码。之后删除了用户下的 .m2 文件夹,包括存储库文件夹。我确实更新了项目并启用了快照/发布的强制更新、maven clean 和 maven build。但没有任何帮助。

pom.xml

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.abc.roster</groupId>
    <artifactId>spring-boot-roster-app</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>spring-boot-roster-app</name>
    <description>Demo project for Spring Boot Roster</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.2.0.BUILD-SNAPSHOT</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>
        <!-- <start-class>com.infosys.roster.SpringBootRosterAppApplication</start-class> -->
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <!--encryption lib -->
        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt</artifactId>
            <version>1.9.2</version>
        </dependency>

        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt-springsecurity3</artifactId>
            <version>1.9.0</version>
        </dependency>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-rest</artifactId>
        </dependency>

        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>

        </dependency>


<!--        <dependency> -->
<!--         <groupId>org.hibernate</groupId> -->
<!--         <artifactId>hibernate-core</artifactId> -->
<!--         <version>5.2.10.Final</version> -->
<!--   </dependency> -->

        <!-- <dependency> -->
        <!-- <groupId>io.springfox</groupId> -->
        <!-- <artifactId>springfox-swagger2</artifactId> -->
        <!-- <version>2.7.0</version> -->
        <!-- <scope>compile</scope> -->
        <!-- </dependency> -->


        <!-- <dependency> -->
        <!-- <groupId>io.springfox</groupId> -->
        <!-- <artifactId>springfox-swagger-ui</artifactId> -->
        <!-- <version>2.7.0</version> -->
        <!-- <scope>compile</scope> -->
        <!-- </dependency> -->

        <!-- <dependency> -->
        <!-- <groupId>io.springfox</groupId> -->
        <!-- <artifactId>springfox-data-rest</artifactId> -->
        <!-- <version>2.7.0</version> -->
        <!-- </dependency> -->
    </dependencies>

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

    <repositories>
        <repository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
        <repository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </repository>
    </repositories>
    <pluginRepositories>
        <pluginRepository>
            <id>spring-snapshots</id>
            <name>Spring Snapshots</name>
            <url>https://repo.spring.io/snapshot</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
        <pluginRepository>
            <id>spring-milestones</id>
            <name>Spring Milestones</name>
            <url>https://repo.spring.io/milestone</url>
        </pluginRepository>
    </pluginRepositories>

</project> 

application.properties

应用程序属性

server.port=
spring.h2.console.path=/h2
spring.h2.console.enabled=true

spring.datasource.url=


spring.datasource.username=
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.platform=h2
spring.datasource.initialization-mode=always

spring.jpa.hibernate.ddl-auto=update
spring.datasource.continue-on-error=true

spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=false

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect

Should remove unknown error in pom.xml and also I must be able to populate values in H2 db.

应该删除 pom.xml 中的未知错误,而且我必须能够在 H2 db 中填充值。

采纳答案by Matthias

answer according to current status

根据当前状态回答

This issuegot fixed:

此问题已修复:

Please install the m2e connector for mavenarchiver plugin 0.17.3 from https://download.eclipse.org/m2e-wtp/releases/1.4/

请从https://download.eclipse.org/m2e-wtp/releases/1.4/为 mavenarchiver 插件 0.17.3 安装 m2e 连接器



obsolete answer

过时的答案

A less profound change than a downgrade from Spring Boot 2.1.5.RELEASEto 2.1.4.RELEASEwould be downgrading only the affected Maven JAR Pluginfrom 3.1.2to 3.1.1as long as this bug exists:

比春季启动降级一个不太深刻的变化2.1.5.RELEASE,以2.1.4.RELEASE将被降级只是受影响的Maven Jar插件3.1.23.1.1只要这个错误存在:

<properties>
    <!-- ... -->
    <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>

回答by AplusKminus

While I cannot reproduce your error (as none of your team mates can either), I have a suggestion, that might help you.

虽然我无法重现您的错误(因为您的队友都无法重现),但我有一个建议,可能会对您有所帮助。

Have you heard of the Byte Order Mark? As it appears on line 1 it is a likely candidate for your troubles. Maybe you changed a setting somewhere that somehow leads to the error. This quote from the Wikipedia article is particularly relevant I think:

你听说过字节顺序标记吗?当它出现在第 1 行时,它很可能是您遇到麻烦的候选者。也许您在某处更改了以某种方式导致错误的设置。我认为维基百科文章中的这句话特别相关:

BOM use is optional. Its presence interferes with the use of UTF-8 by software that does not expect non-ASCII bytes at the start of a file but that could otherwise handle the text stream.

BOM 的使用是可选的。它的存在会干扰软件使用 UTF-8,这些软件不希望文件开头有非 ASCII 字节,但可以以其他方式处理文本流。

回答by fsuwailih

For me I changed in the parent tag of the pom.xml and it solved it change 2.1.5 to 2.1.4 then Maven-> Update Project

对我来说,我更改了 pom.xml 的父标签,它解决了将 2.1.5 更改为 2.1.4 然后 Maven-> 更新项目

回答by pushpendra yadav

For me I changed in the parent tag of the pom.xmland it solved it change 2.1.5 to 2.1.4then Maven-> Update Project. its worked for me also.

对我来说,我更改了pom.xml的父标签,change 2.1.5 to 2.1.4然后解决了它Maven-> Update Project。它也对我有用。

回答by u5146025

There is a bug about Eclipse and spring-boot-starter-parent 2.1.5

有一个关于 Eclipse 和 spring-boot-starter-parent 2.1.5 的错误

"if the maven packaging attribute is war then no problem.The problem is in jar type." So you can also fix this problem by changing packaging type.

“如果maven的包装属性是war那么没问题。问题出在jar类型上。” 所以你也可以通过改变包装类型来解决这个问题。

<packaging>war</packaging>

回答by Stephen

As per the suggestion from @Shravani, in my pom.xml file, I changed my version number in the area from this:

根据@Shravani 的建议,在我的 pom.xml 文件中,我更改了该区域的版本号:

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

to this:

对此:

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

I then right clicked on the project and did a 'Maven -> Update project...'. This made the problem go away for me.

然后我右键单击该项目并执行“Maven -> 更新项目...”。这让我的问题消失了。

回答by mjames276

same problem for me, original code from spring starter demo gives unknown error on line 1:

对我来说同样的问题,来自 spring starter 演示的原始代码在第 1 行给出了未知错误:

<?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>
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.6.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>
...

Changing just the version of 2.1.6.RELEASE to 2.1.4.RELEASE fixes the problem.

仅将 2.1.6.RELEASE 的版本更改为 2.1.4.RELEASE 即可解决此问题。

回答by tksilicon

Got this error on eclipse IDE version 4.10, Spring boot 2.2.0.M4, changed the Spring boot version to 2.2.0.M2 (after many other solutions recommended and it solved the error). Maybe something missing or broken in the latest version of Spring boot starter project module maven POM.

在 Eclipse IDE 版本 4.10,Spring boot 2.2.0.M4 上出现此错误,将 Spring boot 版本更改为 2.2.0.M2(在推荐了许多其他解决方案后,它解决了错误)。也许最新版本的 Spring boot starter 项目模块 maven POM 中缺少或损坏了某些东西。

回答by nitinr708

In my pom.xml file I had to downgrade the version from 2.1.6.RELEASE for spring-boot-starter-parent artifact to 2.1.4.RELEASE

在我的 pom.xml 文件中,我不得不将 spring-boot-starter-parent 工件的版本从 2.1.6.RELEASE 降级到 2.1.4.RELEASE

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

to be changed to

改为

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

And that weird Unknown errordisappeared

那个奇怪的未知错误消失了

回答by user10095279

I updated spring tool suits by going help> check for update.

我通过去help>更新了弹簧工具套装check for update