【问题标题】:org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile Spring Cloudorg.apache.maven.lifecycle.LifecycleExecutionException: 未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile Spring Cloud
【发布时间】:2018-10-05 03:24:29
【问题描述】:

尝试从链接编译项目时遇到以下错误:https://howtodoinjava.com/spring/spring-cloud/consul-service-registration-discovery/。我只是运行 spring-cloud-consul-student 没有任何自定义面临以下错误。所有代码如下所示,供参考。

[ERROR] 无法执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 项目 spring-cloud-consul-student 上的(默认编译):编译 失败:编译失败: [错误] /C:/Users/pashtikar/Documents/MyELC/spring-cloud-consul-student/src/main/java/com/example/howtodoinjava/SpringCloudConsulStudentApplication.java:[5,50] 包 org.springframework.cloud.client.discovery 不存在 [错误] /C:/Users/pashtikar/Documents/MyELC/spring-cloud-consul-student/src/main/java/com/example/howtodoinjava/SpringCloudConsulStudentApplication.java:[8,2] 找不到标志 [错误] 符号:类 EnableDiscoveryClient [错误] -> [帮助 1] org.apache.maven.lifecycle.LifecycleExecutionException:未能执行目标 org.apache.maven.plugins:maven-compiler-plugin:3.1:compile 项目 spring-cloud-consul-student 上的(默认编译):编译 失败 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:213) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:154) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:146) 在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117) 在 org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81) 在 org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56) 在 org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128) 在 org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305) 在 org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192) 在 org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105) 在 org.apache.maven.cli.MavenCli.execute (MavenCli.java:956) 在 org.apache.maven.cli.MavenCli.doMain (MavenCli.java:290) 在 org.apache.maven.cli.MavenCli.main (MavenCli.java:194) 在 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法) 在 sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke (Method.java:498) 在 org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (启动器.java:289) 在 org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:229) 在 org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:415) 在 org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:356) 引起:org.apache.maven.plugin.compiler.CompilationFailureException: 编译失败

SpringCloudConsulStudentApplication

@SpringBootApplication
@EnableDiscoveryClient
public class SpringCloudConsulStudentApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringCloudConsulStudentApplication.class, args);
    }
}

application.properties

server.port=9098
spring.application.name=student-service
management.security.enabled=false

StudentServiceController

@RestController
public class StudentServiceController {
    private static Map<String, List<Student>> schooDB = new HashMap<String, List<Student>>();

    static {
        schooDB = new HashMap<String, List<Student>>();

        List<Student> lst = new ArrayList<Student>();
        Student std = new Student("Sajal", "Class IV");
        lst.add(std);
        std = new Student("Lokesh", "Class V");
        lst.add(std);

        schooDB.put("abcschool", lst);

        lst = new ArrayList<Student>();
        std = new Student("Kajal", "Class III");
        lst.add(std);
        std = new Student("Sukesh", "Class VI");
        lst.add(std);

        schooDB.put("xyzschool", lst);

    }

    @RequestMapping(value = "/getStudentDetailsForSchool/{schoolname}", method = RequestMethod.GET)
    public List<Student> getStudents(@PathVariable String schoolname) {
        System.out.println("Getting Student details for " + schoolname);

        List<Student> studentList = schooDB.get(schoolname);
        if (studentList == null) {
            studentList = new ArrayList<Student>();
            Student std = new Student("Not Found", "N/A");
            studentList.add(std);
        }
        return studentList;
    }
}

【问题讨论】:

  • 你的 pom 在这里比你的代码更重要

标签: java spring-cloud consul


【解决方案1】:

试试这些:

1.按照以下步骤:- Window --> Preference --> Installed JREs --> Change path of JRE to JDK(add)。还要确保你的 POM 中的 jdk 版本与你的 java 编译器的版本相同。

2.你有没有检查你的项目所在的目录路径。可能有访问限制。

3.检查您的互联网连接,是否可以访问https://repo.spring.io

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-04
    • 2021-03-11
    • 2015-05-03
    • 2019-04-09
    • 2017-02-18
    • 2013-05-30
    • 1970-01-01
    相关资源
    最近更新 更多