为了让maven的jdk编译版本一致, 使用maven-compiler-plugin插件来协助管理

建议新建maven项目后的第一步就是配置该插件

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>

使用encoding参数课解决java文件的编码问题

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>

合起来就是

<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<encoding>UTF8</encoding>
</configuration>
</plugin>
</plu

默认jdk版本不匹配出现的异常信息为

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project springJMS: Compilation failure: Compilation failure:
[ERROR] /home/frank/programcode/SpringJMSSample/src/main/java/huangbowen/net/jms/MessageSender.java:[6,1] error: annotations are not supported in -source 1.3
[ERROR]
[ERROR] (use -source 5 or higher to enable annotations)
[ERROR] /home/frank/programcode/SpringJMSSample/src/main/java/net/EmbedBrokerApp.java:[5,7] error: static import declarations are not supported in -source 1.3
[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

jdk1.8 的配置:

      <!-- the Maven compiler plugin will compile Java source files -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.</version>
<configuration>
<encoding>UTF-</encoding>
</configuration>
</plugin>

scala 2.11.12 的配置

      <!-- the Maven Scala plugin will compile Scala source files -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>

maven-compiler-plugin 指定jdk的版本和编码的更多相关文章

  1. maven中如何指定jdk的版本

    问题再现: 当我们每次创建maven项目时,jdk的默认版本是1.5,而我们一般机器上安装的是1.7以上的版本,jdk版本不一样,遇到这种问题,有两种解决办法: 至于右键设置jdk版本不推荐,在此不作 ...

  2. [Maven] - Eclipse "maven compiler plugin" 冲突解决

    刚安装最新的Maven 3.2.5,在eclipse中使用maven的Run As->Maven Install,总会提示: Failed to execute goal org.apache. ...

  3. maven 编译插件指定jdk版本的两种方式

    第一种方式: <plugin> <artifactId>maven-compiler-plugin</artifactId> <configuration&g ...

  4. maven 设置pom 指定jdk版本

    <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</acti ...

  5. 设置maven创建工程的jdk编译版本

    方式一:在maven的主配置文件中指定创建工程时使用jdk1.8版本 <profile> <id>jdk-1.8</id> <activation> & ...

  6. maven pom.xml指定jdk

    <plugins> <!-- 指定jdk --> <plugin> <groupId>org.apache.maven.plugins</grou ...

  7. pom指定java编译版本和编码

    方法一 <properties> <!-- 文件拷贝时的编码 --> <project.build.sourceEncoding>UTF-8</project ...

  8. maven pom.xml设置jdk编译版本为1.8

    <build> <finalName>myweb</finalName> <plugins> <!--JDK版本 --> <plugi ...

  9. Linux环境下TomCat使用指定JDK的版本

    服务器是web服务器,在上面安装了jdk1.7和jdk1.8.及多个tomcat应用,默认/etc/profile 配置的jdk1.7,大部分tomcat应用使用的也是jdk1.7, 但目前有一个新项 ...

随机推荐

  1. Jmeter-安装与配置

    前言 越长大越无脑,很多东西还是很容易忘记,哈哈,虽然网上也有很多关于Jmeter的安装配置教程,但还是想在自己的博客上记录下,便于以后查阅. JMeter的安装配置过程 我的环境信息如下: 操作系统 ...

  2. 如何对CentOS FTP服务配置

    根据很多人对CentOS FTP服务的不解,我觉得应该对CentOS FTP服务做出一定的解释. 1.安装 一般在CentOS上都自动安装了vsftd,若没有安装则可以使用以下步骤进行安装yum -y ...

  3. Mac使用终端安装Homebrew(brew)

    Homebrew简称brew,OSX上的软件包管理工具,在Mac终端可以通过brew安装.更新.卸载软件. 1.打开终端直接输入下面指令回车: // ruby -e "$(curl -fsS ...

  4. 02:OC和C对比

    1.源文件对比 C语言中常见源文件.h头文件,.c文件 文件扩展名 源类型 .h 头文件,用于存放函数声明 .c C语言源文件,用于实现头文件中声明的方法 OC中的源文件.h头文件,.m与.mm的实现 ...

  5. 当有多个form表单请求时如何处理?

    问题:当有多个表单请求时如何处理?两种获取form表单 name属性值来区分是哪一个form表单.问题:如何获取name的值呢?<form name="myForm" met ...

  6. 工作随笔——elasticsearch 6.6.1安装(docker-compose方式)

    docker-compose.yml: version: '2.2' services: es1: image: docker.elastic.co/elasticsearch/elasticsear ...

  7. NLog配置JsonLayout中文输出为unicode问题

    日志输出现要改为json格式,网上查询layout配置为JsonLayout就可以了,结果发现输出中文为unicode编码,看很多文章说配置encode="false"就可以了,结 ...

  8. ASP.NET MVC 导入Excel文件

    一:view部分 <form method="post" enctype="multipart/form-data" action="/Posi ...

  9. [学习笔记]min_25筛

    神佬yyb 神佬zsy 想不到花了两个小时的时间看 \(min\_25\) 筛就看懂了 实际去追了一下魔禁3 我们先举个例子.如求 \[\sum_{i=1}^{n}f(i)\] 其中 \(f(i)\) ...

  10. Spring学习笔记3——消息队列(rabbitmq), 发送邮件

    本节的内容是用户注册时,将邮箱地址先存入rabbitmq队列,之后返回给用户注册成功:之后消息队列的接收者从队列中获取消息,发送邮件给用户. 一.RabbitMQ介绍     如果之前对rabbitm ...