centos7 安装java8

  1. 下载jdk , tar格式或rpm格式
  2. 安装 rpm -Uvh jdk_your_version_.rpm   # 安装java
  3. 配置环境变量, vim /etc/profile.d/java.sh
export JAVA_HOME=/usr/java/jdk1.8.0_271-amd64/
   export JRE_HOME=/usr/java/jdk1.8.0_271-amd64/jre
   export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH

c中的char和java中的byte

在C中,char是基础数据类型,8位,1个字节。byte不是基础数据类型,一般是typedef unsigned char byte;这样子的,也就是说,byte其实是unsigned char类型,那么也是8位,1个字节。不同的是,char可以表示的范围是-128-127,而byte可以表示的范围是0-255。

在java中,char和byte都是基础数据类型,其中的byte和C中的char类型是一样的,8位,1个字节,-128-127。但是,char类型,是16位,2个字节

Logback configuration error detected

原因: spring-boot-starter-web包的时候他里面默认使用了logback日志,这样就会产生日志包的冲突,其实不只是starter-web包默认引入的logback还有很多的包默认引入的logback包

解决: 需要把 spring-boot-starter-web 放到pom文件中依赖的第一位,在向下执行的时候也会排除所有的默认logger了 。

maven发布的项目打包jsp

从eslipse迁移的Web项目的jsp、js、css等文件都是放到WebContent里,而Maven中,这些文件是放到webapp下的。所以,如果你直接用Maven进行install也就是打包的时候,你的页面相关的文件不会被打包进去,你会发现打好的war包里只有src下的.class文件和一些配置文件。那么如何将页面等文件也包含进去呢?

<build>
	<finalName>projectName</finalName>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-war-plugin</artifactId>
			<version>3.2.3</version>					
			<configuration>
				<!--指定web.xml文件的位置-->
				<webXml>WebContent/WEB-INF/web.xml</webXml>				
				<!--指定jsp等文件所在位置-->   
				<warSourceDirectory>WebContent</warSourceDirectory>
			</configuration>
		</plugin>
	</plugins>
</build>

validatorUtil 工具类校验fastjson转对象的参数

  1. 工具类
import org.hibernate.validator.HibernateValidator;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;

import javax.validation.Validation;
import java.util.Set;

public class ValidatorUtil {
    /**
     * 开启快速结束模式 failFast (true)
     */
    private static final Validator validator = Validation.byProvider(HibernateValidator.class).configure().failFast(false).buildValidatorFactory().getValidator();

    /**
     * 校验对象
     *
     * @param t bean
     * @param groups 校验组
     * @return ValidResult
     */
    public static <T> ValidResult validateBean(T t, Class<?>...groups) {
        ValidResult result = new ValidResult();
        Set<ConstraintViolation<T>> violationSet = validator.validate(t,groups);
        boolean hasError = violationSet != null && violationSet.size() > 0;
        result.setHasErrors(hasError);
        if (hasError) {
            for (ConstraintViolation<T> violation : violationSet) {
                result.addError(violation.getPropertyPath().toString(), violation.getMessage());
            }
        }
        return result;
    }
    /**
     * 校验bean的某一个属性
     *
     * @param obj          bean
     * @param propertyName 属性名称
     * @return ValidResult
     */
    public static <T> ValidResult validateProperty(T obj, String propertyName) {
        ValidResult result = new ValidResult();
        Set<ConstraintViolation<T>> violationSet = validator.validateProperty(obj, propertyName);
        boolean hasError = violationSet != null && violationSet.size() > 0;
        result.setHasErrors(hasError);
        if (hasError) {
            for (ConstraintViolation<T> violation : violationSet) {
                result.addError(propertyName, violation.getMessage());
            }
        }
        return result;
    }
}

2. ValidResult 校验结果类

import java.util.ArrayList;
import java.util.List;

public class ValidResult {

    /**
     * 是否有错误
     */
    private boolean hasErrors;

    /**
     * 错误信息
     */
    private final List<ValidErrorMessage> errors;

    public ValidResult() {
        this.errors = new ArrayList<>();
    }
    public boolean hasErrors() {
        return hasErrors;
    }

    public void setHasErrors(boolean hasErrors) {
        this.hasErrors = hasErrors;
    }

    /**
     * 获取所有验证信息
     * @return 集合形式
     */
    public List<ValidErrorMessage> getAllErrors() {
        return errors;
    }
    /**
     * 获取所有验证信息
     * @return 字符串形式
     */
    public String getErrors(){
        StringBuilder sb = new StringBuilder();
        for (ValidErrorMessage error : errors) {
            sb.append(error.getPropertyPath()).append(":").append(error.getMessage()).append(" ");
        }
        return sb.toString();
    }

    public void addError(String propertyName, String message) {
        this.errors.add(new ValidErrorMessage(propertyName, message));
    }
}

3. 错误类

public class ValidErrorMessage {
    private String propertyPath;

    private String message;

    public String getPropertyPath() {
        return propertyPath;
    }

    public void setPropertyPath(String propertyPath) {
        this.propertyPath = propertyPath;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public ValidErrorMessage() {
    }

    public ValidErrorMessage(String propertyPath, String message) {
        this.propertyPath = propertyPath;
        this.message = message;
    }
}

4. 校验类

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;

public class CheckDataUpdateTimeJson {
    @NotBlank(message = "token不能为空!")
    private String token;
    
    public void setToken(String token) {
        this.token = token;
    }
    public String getToken() {
        return token;
    }
}

5. 使用

String requestJson = HelperUtils.convertStreamToString(request.getInputStream());
            CheckDataUpdateTimeJson paramJson = JSON.parseObject(requestJson, CheckDataUpdateTimeJson.class);
            ValidResult validResult = ValidatorUtil.validateBean(paramJson);
            if (validResult.hasErrors()) {
                System.out.println(validResult.getErrors());
            }

Spring 添加 Hibernate Validator支持 Add a provider like Hibernate Validator (RI) to your classpath

  1. 添加依赖
<dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>6.1.2.Final</version>
        </dependency>
<dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>2.0.1.Final</version>
        </dependency>
<dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator-annotation-processor</artifactId>
            <version>6.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.validator</groupId>
            <artifactId>hibernate-validator-cdi</artifactId>
            <version>6.1.2.Final</version>
        </dependency>
<dependency>
            <groupId>jakarta.validation</groupId>
            <artifactId>jakarta.validation-api</artifactId>
            <version>2.0.2</version>
        </dependency>
<dependency>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
            <version>3.4.1.Final</version>
        </dependency>
<dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>jakarta.el</artifactId>
            <version>3.0.3</version>
        </dependency>
<dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>8.0.1</version>
            <scope>provided</scope>
        </dependency>

2. 向容器里注册一个处理器:

@Configuration
@EnableWebMvc
public class WebRootConfig {

    @Bean
    public MethodValidationPostProcessor methodValidationPostProcessor() {
        return new MethodValidationPostProcessor();
    }
}

3. 增加验证类

public class AppLoginParam {
    @NotNull(message = "userName不能为空")
    private String userName;
    @NotNull(message = "password不能为空")
    private String password;
    
    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}

4. Controller增加验证

    @RequestMapping("/login")
    @ResponseBody
    public AjaxJson login(@Valid @RequestBody AppLoginParam requestParam, BindingResult bindingResult) {
        AjaxJson res = new AjaxJson();
        Integer code = response.getStatus();
        res.setCode(String.valueOf(code));
        res.setStatus(false);
        // validator 验证
        if (bindingResult.hasErrors()) {
            res.setMessage(bindingResult.getFieldError().getDefaultMessage());
            return res;
        }
// do something....
}

spring的bean在多线程中注入的问题

问题描述

在spring中,如果需要在异步线程中注入bean,会发现bean是空的情况。原因据说是spring bean 出于线程安全考虑,不得注入bean至线程类(Runnable)。
代码如下:

public class DealThreadTask implements Runnable{



    @Autowired
    private DealService dealService;


    @Override
    public void run() {

    //  DealService dealService=holder.getBean("dealService");
        System.out.println("dealService-->"+dealService);
        dealService.deal("andy", "李琳", 100d);


    }

}

说明spring在DealThreadTask中未能将dealService注入进去。

解决方法

Spring API 中有ApplicationContextAware 这个接口,实现了这个接口的类,可以在容器初始化完成中获得容器,从而可以获得容器中所有的bean。

public class ApplicationContextHolder implements ApplicationContextAware {

     private static ApplicationContext applicationContext;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ApplicationContextHolder.applicationContext=applicationContext;
        System.out.println("applicationContext---->"+applicationContext);
    }

     public static <T> T getBean(Class<T> clazz){
         return applicationContext.getBean(clazz);
   }

     public static Object getBean(String name) {

         if (applicationContext==null) {
             System.out.println("applicationContext为空");
        }
            return  applicationContext.getBean(name);

     }
}

然后,在xml配置文件中,需要将这个类配置进去。

<bean id="applicationContextHolder"  class="com.test.spring.tx.multi.ApplicationContextHolder"></bean>

这样,在异步线程中的DealThreadTask 中,通过手动的applicationContextHolder的getBean方法,就可以获取所需要的bean。

public class DealThreadTask implements Runnable{



    @Autowired
    private ApplicationContextHolder holder;



    @Override
    public void run() {

        DealService dealService=holder.getBean("dealService");
        System.out.println("dealService-->"+dealService);
        dealService.deal("andy", "李琳", 100d);


    }

}

补充:Spring中出现:No bean named ‘XXX’ available问题解决

注解如果没有指定bean的名字,默认为小写开头的类名。例如类名是ProvincialServiceImpl,则spring返回provincialServiceImpl的bean名。

maven打包依赖到lib目录

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>target/lib</outputDirectory>
                        <excludeTransitive>false</excludeTransitive>
                        <stripVersion>true</stripVersion>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <!--java代码打包插件,不会将依赖也打包-->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
        </plugin>
    </plugins>
</build>

在类路径或引导类路径中找不到程序包 java.lang

这是在基于 maven 编写java项目的时候,使用 mvn install 时发生的异常,异常信息如下

[源文件的搜索路径: /Users/Frank/workspace-java/project/app-web/src/main/java,/Users/Frank/workspace-java/project/app-web/target/generated-sources/annotations]  [类文件的搜索路径: /Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/rt.jar;/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/jce.jar,/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/ext/cldrdata.jar,/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/ext/dnsns.jar,/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/ext/jaccess.jar,/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/ext/jfxrt.jar,/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/ext/localedata.jar,/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/ext/nashorn.jar,/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/ext/sunec.jar,/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar,/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar,/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/lib/ext/zipfs.jar,/System/Library/Java/Extensions/MRJToolkit.jar,/Users/Frank/workspace-java/projects/app-web/target/classes,/Users/Frank/workspace-java/hnProjects/app-configs/target/app-configs-1.0-SNAPSHOT.jar,/Users/Frank/workspace-java/hnProjects/app-utils/target/app-utils-1.0-SNAPSHOT.jar,/Users/Frank/.m2/repository/org/apache/commons/commons-lang3/3.3.2/commons-lang3-3.3.2.jar,/Users/Frank/.m2/repository/commons-httpclient/commons-httpclient/3.1/commons-httpclient-3.1.jar,/Users/Frank/.m2/repository/commons-codec/commons-codec/1.9/commons-codec-1.9.jar,/Users/Frank/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar,/Users/Frank/.m2/repository/org/apache/httpcomponents/httpclient/4.3.6/httpclient-4.3.6.jar,/Users/Frank/.m2/repository/org/apache/httpcomponents/httpcore/4.3.3/httpcore-4.3.3.jar,/Users/Frank/.m2/repository/commons-logging/commons-logging/1.1.3/commons-logging-1.1.3.jar,/Users/Frank/.m2/repository/commons-beanutils/commons-beanutils/1.9.2/commons-beanutils-1.9.2.jar,/Users/Frank/.m2/repository/org/apache/ant/ant/1.9.4/ant-1.9.4.jar,/Users/Frank/.m2/repository/org/apache/ant/ant-launcher/1.9.4/ant-launcher-1.9.4.jar,/Users/Frank/.m2/repository/net/sf/json-lib/json-lib/2.4/json-lib-2.4-jdk15.jar,/Users/Frank/.m2/repository/commons-lang/commons-lang/2.5/commons-lang-2.5.jar,/Users/Frank/.m2/repository/net/sf/ezmorph/ezmorph/1.0.6/ezmorph-1.0.6.jar,/Users/Frank/.m2/repository/com/github/junrar/junrar/0.7/junrar-0.7.jar,/Users/Frank/.m2/repository/com/github/junrar/junrar/0.7/commons-logging-api-1.1.jar,/Users/Frank/.m2/repository/com/github/junrar/junrar/0.7/commons-vfs2-2.0.jar,/Users/Frank/.m2/repository/com/github/junrar/junrar/0.7/commons-logging-1.1.1.jar,/Users/Frank/.m2/repository/com/github/junrar/junrar/0.7/maven-scm-api-1.4.jar,/Users/Frank/.m2/repository/com/github/junrar/junrar/0.7/plexus-utils-1.5.6.jar,/Users/Frank/.m2/repository/com/github/junrar/junrar/0.7/maven-scm-provider-svnexe-1.4.jar,/Users/Frank/.m2/repository/com/github/junrar/junrar/0.7/maven-scm-provider-svn-commons-1.4.jar,/Users/Frank/.m2/repository/com/github/junrar/junrar/0.7/regexp-1.3.jar,/Users/Frank/.m2/repository/commons-logging/commons-logging-api/1.1/commons-logging-api-1.1.jar,/Users/Frank/.m2/repository/org/apache/commons/commons-vfs2/2.0/commons-vfs2-2.0.jar,/Users/Frank/.m2/repository/org/apache/maven/scm/maven-scm-api/1.4/maven-scm-api-1.4.jar,/Users/Frank/.m2/repository/org/codehaus/plexus/plexus-utils/1.5.6/plexus-utils-1.5.6.jar,/Users/Frank/.m2/repository/org/apache/maven/scm/maven-scm-provider-svnexe/1.4/maven-scm-provider-svnexe-1.4.jar,/Users/Frank/.m2/repository/org/apache/maven/scm/maven-scm-provider-svn-commons/1.4/maven-scm-provider-svn-commons-1.4.jar,/Users/Frank/.m2/repository/regexp/regexp/1.3/regexp-1.3.jar,/Users/Frank/.m2/repository/dom4j/dom4j/1.6.1/dom4j-1.6.1.jar,/Users/Frank/.m2/repository/xml-apis/xml-apis/1.0.b2/xml-apis-1.0.b2.jar,/Users/Frank/.m2/repository/org/jsoup/jsoup/1.8.1/jsoup-1.8.1.jar,/Users/Frank/.m2/repository/commons-fileupload/commons-fileupload/1.3.1/commons-fileupload-1.3.1.jar,/Users/Frank/.m2/repository/commons-io/commons-io/2.4/commons-io-2.4.jar,/Users/Frank/.m2/repository/joda-time/joda-time/2.6/joda-time-2.6.jar,/Users/Frank/.m2/repository/com/google/code/gson/gson/2.3.1/gson-2.3.1.jar,/Users/Frank/.m2/repository/com/google/guava/guava/18.0/guava-18.0.jar,/Users/Frank/.m2/repository/com/googlecode/xmemcached/xmemcached/2.0.0/xmemcached-2.0.0.jar,/Users/Frank/.m2/repository/javax/mail/mail/1.4.1/mail-1.4.1.jar,/Users/Frank/.m2/repository/javax/mail/mail/1.4.1/activation.jar,/Users/Frank/.m2/repository/javax/activation/activation/1.1/activation-1.1.jar,/Users/Frank/.m2/repository/com/belerweb/pinyin4j/2.5.0/pinyin4j-2.5.0.jar,/Users/Frank/.m2/repository/org/jdom/jdom/2.0.2/jdom-2.0.2.jar,/Users/Frank/.m2/repository/org/apache/poi/poi-scratchpad/3.10.1/poi-scratchpad-3.10.1.jar,/Users/Frank/.m2/repository/org/apache/poi/poi/3.11/poi-3.11.jar,/Users/Frank/.m2/repository/org/springframework/spring-core/4.1.4.RELEASE/spring-core-4.1.4.RELEASE.jar,/Users/Frank/.m2/repository/org/springframework/spring-context/4.1.4.RELEASE/spring-context-4.1.4.RELEASE.jar,/Users/Frank/.m2/repository/org/springframework/spring-aop/4.1.4.RELEASE/spring-aop-4.1.4.RELEASE.jar,/Users/Frank/.m2/repository/aopalliance/aopalliance/1.0/aopalliance-1.0.jar,/Users/Frank/.m2/repository/org/springframework/spring-beans/4.1.4.RELEASE/spring-beans-4.1.4.RELEASE.jar,/Users/Frank/.m2/repository/org/springframework/spring-expression/4.1.4.RELEASE/spring-expression-4.1.4.RELEASE.jar,/Users/Frank/.m2/repository/org/springframework/spring-context-support/4.1.4.RELEASE/spring-context-support-4.1.4.RELEASE.jar,/Users/Frank/.m2/repository/org/springframework/spring-webmvc/4.1.4.RELEASE/spring-webmvc-4.1.4.RELEASE.jar,/Users/Frank/.m2/repository/org/springframework/spring-web/4.1.4.RELEASE/spring-web-4.1.4.RELEASE.jar,/Users/Frank/.m2/repository/org/springframework/spring-jdbc/4.1.4.RELEASE/spring-jdbc-4.1.4.RELEASE.jar,/Users/Frank/.m2/repository/org/springframework/spring-tx/4.1.4.RELEASE/spring-tx-4.1.4.RELEASE.jar,/Users/Frank/.m2/repository/org/springframework/spring-orm/4.1.4.RELEASE/spring-orm-4.1.4.RELEASE.jar,/Users/Frank/.m2/repository/org/aspectj/aspectjweaver/1.8.4/aspectjweaver-1.8.4.jar,/Users/Frank/.m2/repository/org/hibernate/hibernate-core/4.3.7.Final/hibernate-core-4.3.7.Final.jar,/Users/Frank/.m2/repository/org/jboss/logging/jboss-logging/3.1.3.GA/jboss-logging-3.1.3.GA.jar,/Users/Frank/.m2/repository/org/jboss/logging/jboss-logging-annotations/1.2.0.Beta1/jboss-logging-annotations-1.2.0.Beta1.jar,/Users/Frank/.m2/repository/org/jboss/spec/javax/transaction/jboss-transaction-api_1.2_spec/1.0.0.Final/jboss-transaction-api_1.2_spec-1.0.0.Final.jar,/Users/Frank/.m2/repository/org/hibernate/common/hibernate-commons-annotations/4.0.5.Final/hibernate-commons-annotations-4.0.5.Final.jar,/Users/Frank/.m2/repository/org/hibernate/javax/persistence/hibernate-jpa-2.1-api/1.0.0.Final/hibernate-jpa-2.1-api-1.0.0.Final.jar,/Users/Frank/.m2/repository/org/javassist/javassist/3.18.1-GA/javassist-3.18.1-GA.jar,/Users/Frank/.m2/repository/antlr/antlr/2.7.7/antlr-2.7.7.jar,/Users/Frank/.m2/repository/org/jboss/jandex/1.1.0.Final/jandex-1.1.0.Final.jar,/Users/Frank/.m2/repository/org/hibernate/hibernate-entitymanager/4.3.7.Final/hibernate-entitymanager-4.3.7.Final.jar,/Users/Frank/.m2/repository/org/hibernate/hibernate-ehcache/4.3.7.Final/hibernate-ehcache-4.3.7.Final.jar,/Users/Frank/.m2/repository/org/hibernate/hibernate-validator/5.1.3.Final/hibernate-validator-5.1.3.Final.jar,/Users/Frank/.m2/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar,/Users/Frank/.m2/repository/com/fasterxml/classmate/1.0.0/classmate-1.0.0.jar,/Users/Frank/.m2/repository/org/freemarker/freemarker/2.3.21/freemarker-2.3.21.jar,/Users/Frank/.m2/repository/net/sf/ehcache/ehcache-core/2.6.10/ehcache-core-2.6.10.jar,/Users/Frank/.m2/repository/com/alibaba/fastjson/1.2.4/fastjson-1.2.4.jar,/Users/Frank/.m2/repository/com/alibaba/druid/1.0.12/druid-1.0.12.jar,/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/../lib/jconsole.jar,/Library/Java/JavaVirtualMachines/jdk1.8.0_73.jdk/Contents/Home/jre/../lib/tools.jar,/Users/Frank/.m2/repository/mysql/mysql-connector-java/5.1.34/mysql-connector-java-5.1.34.jar,/Users/Frank/.m2/repository/com/microsoft/sqlserver/sqljdbc4/4.0/sqljdbc4-4.0.jar,/Users/Frank/.m2/repository/org/slf4j/slf4j-api/1.7.9/slf4j-api-1.7.9.jar,/Users/Frank/workspace-java/hnProjects/app-dao/target/app-dao-1.0-SNAPSHOT.jar,/Users/Frank/workspace-java/hnProjects/app-service/target/app-service-1.0-SNAPSHOT.jar,/Users/Frank/.m2/repository/javax/servlet/jsp/jstl/javax.servlet.jsp.jstl-api/1.2.1/javax.servlet.jsp.jstl-api-1.2.1.jar,/Users/Frank/.m2/repository/javax/el/javax.el-api/2.2.4/javax.el-api-2.2.4.jar,/Users/Frank/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar,/Users/Frank/.m2/repository/javax/servlet/jsp/javax.servlet.jsp-api/2.3.1/javax.servlet.jsp-api-2.3.1.jar,.]  致命错误: 在类路径或引导类路径中找不到程序包 java.lang  [INFO] -------------------------------------------------------------  [ERROR] COMPILATION ERROR :   [INFO] -------------------------------------------------------------  [ERROR] An unknown compilation problem occurred  [INFO] 1 error  [INFO] -------------------------------------------------------------  [INFO] ------------------------------------------------------------------------  [INFO] Reactor Summary:  [INFO]   [INFO] Projects :: APP :: Parent ........................... SUCCESS [  0.357 s]  [INFO] Projects :: APP :: Utils ............................ SUCCESS [  1.257 s]  [INFO] Projects :: APP :: Configs .......................... SUCCESS [  0.374 s]  [INFO] Projects :: APP :: Dao .............................. SUCCESS [  0.172 s]  [INFO] Projects :: APP :: Service .......................... SUCCESS [  0.152 s]  [INFO] Projects :: APP :: Admin ............................ SUCCESS [  1.273 s]  [INFO] Projects :: APP :: Web .............................. FAILURE [  0.081 s]  [INFO] xxx ................................................. SKIPPED  [INFO] ------------------------------------------------------------------------  [INFO] BUILD FAILURE  [INFO] ------------------------------------------------------------------------  [INFO] Total time: 5.426 s  [INFO] Finished at: 2016-07-22T21:26:15+08:00  [INFO] Final Memory: 39M/310M  [INFO] ------------------------------------------------------------------------  [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.2:compile (default-compile) on project app-web: Compilation failure  [ERROR] An unknown compilation problem occurred  [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  [ERROR]   [ERROR] After correcting the problems, you can resume the build with the command  [ERROR]   mvn  -rf :app-web  

原因

原因在于 compiler 插件的配置。


 <plugin>   
<groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>   <version>${maven.compiler.version}</version>
   <configuration>     
<source>${java.version}</source>
     <target>${java.version}</target>     <encoding>${project.build.sourceEncoding}</encoding>     <showWarnings>true</showWarnings>     
<compilerArguments>       
<verbose />      
 <!-- 这个配置很特殊:windows下使用分号(;)分隔,linux/mac下使用冒号(:)分隔 -->       <bootclasspath>${java.home}/lib/rt.jar;${java.home}/lib/jce.jar</bootclasspath>     </compilerArguments>   
</configuration> 
 </plugin>  <!-- ... -->  配置中14行的分隔符问题,在windows下使

配置中分隔符问题,在windows下使用maven 应该使用分号(;)分隔,linux/mac 下使用(:)分隔。