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

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

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.apache.maven.plugins</groupId>
  5. <artifactId>maven-compiler-plugin</artifactId>
  6. <configuration>
  7. <source>1.7</source>
  8. <target>1.7</target>
  9. </configuration>
  10. </plugin>
  11. </plugins>
  12. </build>

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

  1. <plugins>
  2. <plugin>
  3. <groupId>org.apache.maven.plugins</groupId>
  4. <artifactId>maven-compiler-plugin</artifactId>
  5. <executions>
  6. <execution>
  7. <id>default-compile</id>
  8. <phase>compile</phase>
  9. <goals>
  10. <goal>compile</goal>
  11. </goals>
  12. </execution>
  13. </executions>
  14. <configuration>
  15. <encoding>UTF-8</encoding>
  16. </configuration>
  17. </plugin>
  18. </plugins>

合起来就是

  1. <plugins>
  2. <plugin>
  3. <groupId>org.apache.maven.plugins</groupId>
  4. <artifactId>maven-compiler-plugin</artifactId>
  5. <version>3.3</version>
  6. <configuration>
  7. <source>1.7</source>
  8. <target>1.7</target>
  9. <encoding>UTF8</encoding>
  10. </configuration>
  11. </plugin>
  12. </plu

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

  1. [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:
  2. [ERROR] /home/frank/programcode/SpringJMSSample/src/main/java/huangbowen/net/jms/MessageSender.java:[6,1] error: annotations are not supported in -source 1.3
  3. [ERROR]
  4. [ERROR] (use -source 5 or higher to enable annotations)
  5. [ERROR] /home/frank/programcode/SpringJMSSample/src/main/java/net/EmbedBrokerApp.java:[5,7] error: static import declarations are not supported in -source 1.3
  6. [ERROR] -> [Help 1]
  7. [ERROR]
  8. [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
  9. [ERROR] Re-run Maven using the -X switch to enable full debug logging.
  10. [ERROR]
  11. [ERROR] For more information about the errors and possible solutions, please read the following articles:
  12. [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

jdk1.8 的配置:

  1. <!-- the Maven compiler plugin will compile Java source files -->
  2. <plugin>
  3. <groupId>org.apache.maven.plugins</groupId>
  4. <artifactId>maven-compiler-plugin</artifactId>
  5. <version>3.6.</version>
  6. <configuration>
  7. <source>1.8</source>
  8. <target>1.8</target>
  9. </configuration>
  10. </plugin>
  11. <plugin>
  12. <groupId>org.apache.maven.plugins</groupId>
  13. <artifactId>maven-resources-plugin</artifactId>
  14. <version>3.0.</version>
  15. <configuration>
  16. <encoding>UTF-</encoding>
  17. </configuration>
  18. </plugin>

scala 2.11.12 的配置

  1. <!-- the Maven Scala plugin will compile Scala source files -->
  2. <plugin>
  3. <groupId>net.alchim31.maven</groupId>
  4. <artifactId>scala-maven-plugin</artifactId>
  5. <version>3.2.</version>
  6. <executions>
  7. <execution>
  8. <goals>
  9. <goal>compile</goal>
  10. <goal>testCompile</goal>
  11. </goals>
  12. </execution>
  13. </executions>
  14. </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. 停止一个java的线程执行

    找了一个停止线程运行的方法,代码如下: public class stopThread extends Thread { private volatile boolean stop = false; ...

  2. spark Graph 的PregelAPI 理解和使用

    spark Graph 的PregelAPI 理解和使用 图本质上是一种递归的数据结构,可以使用Spark GraphX 的PregelAPI接口对图数据进行批量计算, 之前一直不怎么理解Pregel ...

  3. Windows核心编程:第7章 线程调度、优先级和关联性

    Github https://github.com/gongluck/Windows-Core-Program.git //第7章 线程调度.优先级和关联性.cpp: 定义应用程序的入口点. // # ...

  4. netcore 发布 到 windows server IIS

    net core 和普通net 发布没有什么不同,只需要在个别地方注意下: 1. 在visual Studio 2017 发布 2. 把发布好的文件copy到服务器上,并新建一个网站,同时要注意选择无 ...

  5. 定时任务 Wpf.Quartz.Demo.3

    先把全部源码上传,只是一个Demo,希望大家指点一下不足之处,见本文底部. 1.设置界面 2.详情页面 好了,现在慢慢叙述里面的一些方法. 3.实现拷贝的方法: (1) public static v ...

  6. HashSet源码解析

    此文已由作者赵计刚授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 6.1.对于HashSet需要掌握以下几点 HashSet的创建:HashSet() 往HashSet中添加 ...

  7. ViewPager无限滑动

    2016-6-19 前言 View轮播效果在app中很常见,一想到左右滑动的效果就很容易想到使用ViewPager来实现.对于像我们常说的banner这样的效果,具备无限滑动的功能是可以用ViewPa ...

  8. HDU - 2604 Queuing(递推式+矩阵快速幂)

    Queuing Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  9. Python MySQL - 进行数据查询

    #coding=utf-8 import mysql.connector import importlib import sys # reload(sys) # sys.setdefaultencod ...

  10. win7 配置Windows Update 失败,还原更改,无法进入系统

    win7 配置Windows Update 失败,还原更改,无法进入系统 win7 系统安装好后,忘记了需要关闭自动更新,某天自动更新补丁安装失败,进入下图状态,无法进入正常系统. 解决方案一:使用+ ...