【问题标题】:Why am I getting Unknown error in line 1 of pom.xml?为什么我在 pom.xml 的第 1 行出现未知错误?
【发布时间】:2019-10-02 04:28:10
【问题描述】:

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

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

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

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

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

【问题讨论】:

  • 你是说没有其他人对同一个 pom 文件有问题吗?
  • 更新有问题的错误日志
  • @JoakimDanielson 是的,我的团队中没有人面临我正在使用的代码库的问题。只有我面临这个问题
  • 我遇到了完全相同的问题。我从start.spring.io 创建了几个新的 Spring Boot 项目,将项目导入 Spring Tool Suite 后,我的 pom.xml 文件的第 1 行出现“未知错误”。这才从本周开始。
  • @Stephen 你还在面对这个问题吗?将 2.2.0.BUILD-SNAPSHOT 更改为 2.1.4.BUILD-SNAPSHOT 后我能够解决

标签: java maven spring-boot pom.xml


【解决方案1】:

我愚蠢的解决方案是“删除”问题列表中的错误消息。

右键单击 => 选择删除,您会收到一条警告消息,说它可能会回来。 但是即使我做了一个干净的错误消息也没有返回 并全部构建。

TLDR

我从命令行执行了以下操作 "mvn clean" 结果:没有错误

"mvn compile" 结果:Jar build 在目标文件夹中。 结果:屏幕上没有错误。

所以错误是在eclipse中而不是在pom.xml中

我尝试了以下方法:

更新项目 => 右键单击​​ => Maven=> 更新项目

项目 => 干净 自动构建会产生相同的错误消息。

我尝试将 pom.xml 中的包装从 jar 更改为 war 重建...仍然是相同的错误消息。

我尝试了“升级 m2e 连接器”选项。 重建...仍然是相同的错误消息。

我尝试关闭自动重建、清理并退出 Eclipse。 重新启动 Eclipse 并构建所有...仍然是相同的错误消息。

也许上述方法之一为我修复了它,只是没有正确更新或清除 Eclipse 中的问题日志。

【讨论】:

    【解决方案2】:

    只需在 pom.xml 的属性标签中添加以下 maven jar 版本, 3.1.1

    然后按照以下步骤,

    第 1 步:mvn clean

    第 2 步:更新项目

    问题为我解决了!你也应该试试这个:)

    【讨论】:

      【解决方案3】:

      您必须升级 m2e 连接器。 这是一个已知的错误,但有一个解决方案:

      1. 进入 Eclipse 点击“帮助”>“安装新软件...”

      2. 出现一个窗口。在“安装”窗口中:

        2a。进入“Work with”输入框,输入下一个站点位置并回车 https://download.eclipse.org/m2e-wtp/releases/1.4/

        2b。出现大量信息进入“姓名”输入框。选择所有项目

        2c。点击“下一步”按钮。

      完成安装并重新启动 Eclipse。

      【讨论】:

      • 我发现这些说明是实施解决方案的最清晰途径,每个人都说是根本原因问题,需要升级此连接器。 而且,它有效。 :^)
      【解决方案4】:

      在属性标签中添加3.1.1

      问题解决

      https://medium.com/@saannjaay/unknown-error-in-pom-xml-66fb2414991b

      【讨论】:

        【解决方案5】:

        每当您遇到此类错误时,只需更改 发布版本就像 在我的情况下,它在 2.2.7 中显示错误我更改为 2.2.6

        问题:

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

        解决方案:

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

        【讨论】:

          【解决方案6】:

          以下操作对我有用。

          1.转到工具栏中的项目 -> 取消选中“自动构建”

          2.在POM文件中,将spring-boot版本降级为2.1.4 RELEASE。

          3.右键项目名称->选择Maven->点击“更新项目”。 ->确定 等到所有的maven依赖被下载(需要互联网)。

          【讨论】:

            【解决方案7】:

            将 3.1.1 添加到下面的属性中而不是修复问题

            <properties>
                    <java.version>1.8</java.version>
                    <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
            </properties>
            

            只需更新项目 => 右键单击​​ => Maven=> 更新项目

            【讨论】:

            • 这个问题似乎来自 maven-jar-plugin 3.1.2 & 3.2.0。
            • 是的,但是 3.1.1 工作正常,所以我们可以使用那个
            【解决方案8】:

            我在版本 3 中遇到了同样的错误。将 STS 升级到最新版本:4.5.1.RELEASE 后它工作正常。无需更改最新 STS 中的代码或配置。

            【讨论】:

              【解决方案9】:

              您只需要一个最新的 Eclipse 或 Spring 工具套件 4.5 及更高版本。Nothing else.refresh 项目就可以了

              【讨论】:

                【解决方案10】:

                对我来说,从 2.1.6.RELEASE 更改 SpringBoot 2 项目的 pom.xml

                <parent>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-starter-parent</artifactId>
                        <version>2.1.6.REL`enter code here`EASE</version>
                        <relativePath /> <!-- lookup parent from repository -->
                </parent>
                

                到 2.1.4.RELEASE 已验证并有效

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

                【讨论】:

                • 我的意思是 2.1.4.RELEASE。
                • 编辑了我的答案并修正了错字。
                【解决方案11】:

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

                【讨论】:

                  【解决方案12】:

                  在我的 pom.xml 文件中,我不得不将版本从 2.1.6.RELEASE 降级为 spring-boot-starter-parent 工件到 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>
                  

                  改为

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

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

                  【讨论】:

                    【解决方案13】:

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

                    【讨论】:

                      【解决方案14】:

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

                      【讨论】:

                        【解决方案15】:

                        对我来说同样的问题,来自 spring starter demo 的原始代码在第 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>
                        ...
                        

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

                        【讨论】:

                          【解决方案16】:

                          根据当前状态回答

                          This issue 已修复:

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


                          过时的答案

                          与从 Spring Boot 的 2.1.5.RELEASE 降级到 2.1.4.RELEASE 相比,没有那么深刻的变化是只要存在此错误,就仅将 the affected Maven JAR Plugin3.1.2 降级到 3.1.1

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

                          【讨论】:

                          • 最新的 Eclipse (2019-03) 也有同样的问题。根据您的建议将 maven-jar-plugin 从 3.1.2 更改为 3.1.1 解决了这个问题。非常感谢。
                          • 过时的答案是对我有用的解决方案
                          • 为了记录,我的问题通过升级mavenarchiver插件解决了。
                          • 在为mavenarchiver插件安装m2e连接器后,重启maven并做maven -->更新项目-->强制更新快照
                          • 为我安装最新的 m2e 连接器为 mavenarchiver 修复了它
                          【解决方案17】:

                          根据@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>
                          

                          到这里:

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

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

                          【讨论】:

                            【解决方案18】:

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

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

                            <packaging>war</packaging>
                            

                            【讨论】:

                            • 这是为我做的
                            【解决方案19】:

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

                            【讨论】:

                            • 这里也一样!仍然不确定自 2.1.5 以来 spring 父 pom 中是什么导致了这个问题
                            • @fsuwailih 谢谢这个工作。但我想知道为什么它只对某些人有效,而对其他人无效。
                            • 这个解决方案确实有效!我将它从 2.1.6 更改为 2.1.4。但是为什么更高版本会导致该错误?
                            【解决方案20】:

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

                            你听说过Byte Order Mark吗?正如它在第 1 行显示的那样,它可能是您的麻烦的候选者。也许您在某处更改了某个设置,以某种方式导致错误。我认为维基百科文章中的这句话特别相关:

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

                            【讨论】:

                            • 更改父标签的版本后,它神奇地起作用了
                            猜你喜欢
                            • 2019-10-08
                            • 1970-01-01
                            • 2021-11-15
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            • 2016-10-09
                            • 2019-10-04
                            相关资源
                            最近更新 更多