为了让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. STM32F10X-定时器/计数器

    1.STM32F10X的计数器与定时器关系 当时钟连接外脉冲时是计数器:当时钟采用系统内部时钟时是定时器! 2.STM32F10X定时器的时钟源 STM32F10X定时器的时钟不是直接来至于APB1和 ...

  2. 阿里云服务器 OSS的使用限制

    使用限制 更新时间:2019-02-12 16:50:27 编辑 · OSS的使用限制及性能指标如下:   限制项 说明 归档存储 已经存储的数据从冷冻状态恢复到可读取状态需要 1 分钟的等待时间. ...

  3. 团队项目之UML图设计---WeEdit

    团队信息: 学号: 姓名: 本次博客链接: 041602209 黄毓明(临时队长)  https://www.cnblogs.com/mingsonic/p/9820702.html 06160023 ...

  4. Pyenv 安装部署

    Pyenv Pyenv是个多版本Python管理器,可以同时管理多个Python版本共存, 区别于virtualenv. 安装 git clone git://github.com/yyuu/pyen ...

  5. 基于MATLAB的Sobel边缘检测算法实现

    图像边缘就是图像灰度值突变的地方,也就是图像在该部分的像素值变化速度非常之快,就比如在坐标轴上一条曲线有刚开始的平滑突然来个大转弯,在变化出的导数非常大. Sobel算子主要用作边缘检测,它是一离散型 ...

  6. 用jquery将输入的文字的双向绑定

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  7. myeclipse6.6+maven跑springside4.1的demo

    1.安装myeclipse6.6 2.myeclipse6.6安装maven 2.1 删除原有maven. 关闭Eclipse程序, 进入MyEclipse插件目录/eclipse/features ...

  8. Centos 7 安装 PostgreSQL PGAdmin4

    本文只讲PostgreSQL在CentOS 7.x 下的安装,其他系统请查看:https://www.postgresql.org/download PostgreSQL 所用版本为:PostgreS ...

  9. ContentControl as CC和ContentPresenter as CP的使用

    1.CC为文本控件的父类,它继承为control,所以他是控件, 2.CP继承FrameworkElement,所以他是容器,相当于占位符 3.想让控件中能包含子控件就需要用CP,反之用CC就行.(不 ...

  10. Spring Integration Zip不安全解压(CVE-2018-1261)漏洞复现

    不敢说分析,还是太菜了,多学习. 文章来源: 猎户安全实验室 存在漏洞的源码下载地址:https://github.com/spring-projects/spring-integration-ext ...