如何解决配置选项compilerClassName可用的无Java编译器:[null]和编译器:[null]

时间:2018-05-03 11:38:09

标签: jsp spring-boot maven-tomcat-plugin ecj

我有一个启动弹簧启动Hello World程序,它抛出以下错误:

<link rel="preload" as="style" href="…">

我只在Mac上发行,而不是在Windows PC中发布。在我的Mac上,我尝试过使用Eclipse和IntelliJ IDEA CE。 我在这里看了这两篇文章:

How to resolve java.lang.IllegalStateException: No Java compiler available for configuration options compilerClassName

No Java compiler available for configuration options compilerClassName: [null] and compiler: [null]

但这些解决方案对我没有用。

我在这里发布我的代码: 的pom.xml

No Java compiler available for configuration options compilerClassName: [null] and compiler: [null]

控制器:

<?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.mohnish</groupId>
<artifactId>spring-boot-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>

<name>spring-boot-maven</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.1.RELEASE</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>
</properties>

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

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
    </dependency>

    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>

    <!-- Add this -->
    <dependency>
        <groupId>org.eclipse.jdt.core.compiler</groupId>
        <artifactId>ecj</artifactId>
        <version>4.6.1</version>
        <scope>provided</scope>
    </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>

配置:

package com.mohnish.springbootmaven;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HelloController {

@GetMapping("/")
public String hello() {
    return "hello";
 }
}

Jsp Page:

package com.mohnish.springbootmaven;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import   org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class SpringBootMavenApplication  extends         SpringBootServletInitializer {

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

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    return application.sources(SpringBootMavenApplication.class);
}
}

最后我的application.properties:

<%@ page language="java" contentType="text/html; charset=UTF-8" 
pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Hello</title>
</head>
<body>
    Hello World!
</body>

</html>

我也尝试将jsp文件移至spring.mvc.view.prefix=/WEB-INF/jsp spring.mvc.view.suffix=.jsp 而不是/WEB-INF/

任何指针都将受到赞赏。感谢。

0 个答案:

没有答案