maven 指定jdk版本

发布时间:2022-07-11 17:44:04 作者:yexindonglai@163.com 阅读(668)

方式一:properties指定

  1. <properties>
  2. <maven.compiler.source>1.8</maven.compiler.source>
  3. <maven.compiler.target>1.8</maven.compiler.target>
  4. </properties>

方式二:compiler插件指定

  1. <plugin>
  2. <!-- 指定maven编译的jdk版本,如果不指定,maven3默认用jdk 1.5 maven2默认用jdk1.3 -->
  3. <groupId>org.apache.maven.plugins</groupId>
  4. <artifactId>maven-compiler-plugin</artifactId>
  5. <version>3.1</version>
  6. <configuration>
  7. <!-- 一般而言,target与source是保持一致的,但是,有时候为了让程序能在其他版本的jdk中运行(对于低版本目标jdk,源代码中不能使用低版本jdk中不支持的语法),会存在target不同于source的情况 -->
  8. <source>1.8</source> <!-- 源代码使用的JDK版本 -->
  9. <target>1.8</target> <!-- 需要生成的目标class文件的编译版本 -->
  10. <encoding>UTF-8</encoding><!-- 字符集编码 -->
  11. <skipTests>true</skipTests><!-- 跳过测试 -->
  12. <verbose>true</verbose>
  13. <showWarnings>true</showWarnings>
  14. <fork>true</fork><!-- 要使compilerVersion标签生效,还需要将fork设为true,用于明确表示编译版本配置的可用 -->
  15. <executable><!-- path-to-javac --></executable><!-- 使用指定的javac命令,例如:<executable>${JAVA_1_4_HOME}/bin/javac</executable> -->
  16. <compilerVersion>1.3</compilerVersion><!-- 指定插件将使用的编译器的版本 -->
  17. <meminitial>128m</meminitial><!-- 编译器使用的初始内存 -->
  18. <maxmem>512m</maxmem><!-- 编译器使用的最大内存 -->
  19. <compilerArgument>-verbose -bootclasspath ${java.home}\lib\rt.jar</compilerArgument><!-- 这个选项用来传递编译器自身不包含但是却支持的参数选项 -->
  20. </configuration>
  21. </plugin>

关键字Maven