Java 启用预览特性

向右看齐 2022-12-07 01:23 293阅读 0赞

问题

从Java 13开始支持文本块(多行字符串),可以替代从前丑陋的多行字符串拼接。即使是 Java14 该特性也是预览特性。

报错如下:Text Blocks is a preview feature and disabled by default. Use --enable-preview to enable
在这里插入图片描述

解决方案

eclipse

在这里插入图片描述

maven

修改 pom.xml 文件

  1. <project>
  2. ...
  3. <properties>
  4. <java.version>13</java.version>
  5. <maven.compiler.source>13</maven.compiler.source>
  6. <maven.compiler.target>13</maven.compiler.target>
  7. </properties>
  8. <build>
  9. <plugins>
  10. <plugin>
  11. <groupId>org.springframework.boot</groupId>
  12. <artifactId>spring-boot-maven-plugin</artifactId>
  13. <configuration>
  14. <arguments>--enable-preview</arguments>
  15. <jvmArguments>--enable-preview</jvmArguments>
  16. </configuration>
  17. </plugin>
  18. <plugin>
  19. <groupId>org.apache.maven.plugins</groupId>
  20. <artifactId>maven-surefire-plugin</artifactId>
  21. <version>2.22.2</version>
  22. <configuration>
  23. <argLine>--enable-preview</argLine>
  24. </configuration>
  25. </plugin>
  26. <plugin>
  27. <groupId>org.apache.maven.plugins</groupId>
  28. <artifactId>maven-compiler-plugin</artifactId>
  29. <version>3.8.1</version>
  30. <configuration>
  31. <compilerArgs>--enable-preview</compilerArgs>
  32. </configuration>
  33. </plugin>
  34. </plugins>
  35. </build>
  36. ...
  37. </project>

gradle

在 build.gradle 里添加

  1. tasks.withType(JavaCompile) {
  2. options.compilerArgs += "--enable-preview"
  3. }

命令行

编译 javac --enable-preview -source 13 -encoding utf-8 test.java

执行 java --enable-preview test

发表评论

表情:
评论列表 (有 0 条评论,293人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Java 启用特性

    问题 从Java 13开始支持文本块(多行字符串),可以替代从前丑陋的多行字符串拼接。即使是 Java14 该特性也是预览特性。 报错如下:`Text Blocks i

    相关 Flink 1.14 新特性

    简介: 一文了解 Flink 1.14 版本新特性及最新进展 > 本文由社区志愿者陈政羽整理,内容源自阿里巴巴技术专家宋辛童 (五藏) 在 8 月 7 日线上 Flink M