版本 2.1.7 的 Maven 配置问题 - Spring Boot

Posted

技术标签:

【中文标题】版本 2.1.7 的 Maven 配置问题 - Spring Boot【英文标题】:Maven Configuration Problem with Version 2.1.7 - Spring Boot 【发布时间】:2020-01-05 12:34:08 【问题描述】:

当我尝试使用“v 2.1.7”的新版本创建 Spring Boot 项目时

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

这次它通过以下错误:

描述资源路径位置 类型 未知 pom.xml /demo-1 line 1 Maven 配置问题

如果我要用名称空间将这个新版本替换为我以前在 porm.xml 文件中的旧版本,它的工作良好且没有任何错误, 如果我删除了 .m2 文件夹并重新安装 eclipse,那么它对新版本的支持,但我想将现有的 eclipse 与新版本的 Spring Boot 一起使用,我该怎么办。

是否可以更新现有的 .m2 文件夹?

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 https://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.7.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo-1</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo-1</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

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

</project>

当我这次尝试安装 maven 时出现错误显示

[INFO] Scanning for projects...
[INFO] 
[INFO] -------------------------< com.example:demo-1 >-------------------------
[INFO] Building demo-1 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo-1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 0 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo-1 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to D:\Enternship\SPRING BOOT\demo-1\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.933 s
[INFO] Finished at: 2019-09-02T18:45:56+05:30
[INFO] ------------------------------------------------------------------------
[WARNING] The requested profile "pom.xml" could not be activated because it does not exist.
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project demo-1: Compilation failure
[ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

【问题讨论】:

你能发布完整的pom.xml 文件吗? 在纯命令行上运行最好的完整错误输出... 您的文件是否真的命名为 porm.xml 还是问题中的拼写错误? 对不起,拼写错误,其实名字是pom.xml 错误告诉你出了什么问题[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project demo-1: Compilation failure [ERROR] No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?您正在使用 JRE 而不是 JDK 运行构建(后者确实包含 javac 前者不会因此出现错误)。跨度> 【参考方案1】:

只需配置JDK路径即可

    右键单击项目 点击属性 键入 java 构建路径并转到 java 构建路径 点击库 点击JRE系统库 编辑 点击备用 JRE 点击已安装的 JRE 点击添加 选择标准虚拟机 点击下一步 放置您的 JDK 路径并选择它

这样你就不会看到错误了

=>No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

【讨论】:

以上是关于版本 2.1.7 的 Maven 配置问题 - Spring Boot的主要内容,如果未能解决你的问题,请参考以下文章

MAVEN本地下载安装

jmeter接口测试CI建设:服务器上配置安装jdk和maven

Maven配置默认使用的JDK版本

Maven -- 版本管理 & 资源配置(资源加载属性值)

maven 配置jdk版本编译

没有版本的jar包怎么在maven 里的pom配置