Java 启用预览特性
        【摘要】 
                    
                        
                    
                    问题 
从Java 13开始支持文本块(多行字符串),可以替代从前丑陋的多行字符串拼接。即使是 Java14 该特性也是预览特性。 
报错如下:Text Blocks is a preview featu...
    
    
    
    问题
从Java 13开始支持文本块(多行字符串),可以替代从前丑陋的多行字符串拼接。即使是 Java14 该特性也是预览特性。
报错如下:Text Blocks is a preview feature and disabled by default. Use --enable-preview to enable
 
解决方案
eclipse

maven
修改 pom.xml 文件
<project>
	...
	<properties>
		<java.version>13</java.version>
		<maven.compiler.source>13</maven.compiler.source>
		<maven.compiler.target>13</maven.compiler.target>
	</properties>
	
	<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <arguments>--enable-preview</arguments>
                    <jvmArguments>--enable-preview</jvmArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.22.2</version>
                <configuration>
                    <argLine>--enable-preview</argLine>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <compilerArgs>--enable-preview</compilerArgs>
                </configuration>
            </plugin>
        </plugins>
    </build>
	...
</project>
  
 - 1
 - 2
 - 3
 - 4
 - 5
 - 6
 - 7
 - 8
 - 9
 - 10
 - 11
 - 12
 - 13
 - 14
 - 15
 - 16
 - 17
 - 18
 - 19
 - 20
 - 21
 - 22
 - 23
 - 24
 - 25
 - 26
 - 27
 - 28
 - 29
 - 30
 - 31
 - 32
 - 33
 - 34
 - 35
 - 36
 - 37
 - 38
 
gradle
在 build.gradle 里添加
tasks.withType(JavaCompile) {
    options.compilerArgs += "--enable-preview"
}
  
 - 1
 - 2
 - 3
 
命令行
编译 javac --enable-preview -source 13 -encoding utf-8 test.java
执行 java --enable-preview test
文章来源: blog.csdn.net,作者:福州-司马懿,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/chy555chy/article/details/108585027
        【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
            cloudbbs@huaweicloud.com
        
        
        
        
        
        
        - 点赞
 - 收藏
 - 关注作者
 
            
           
评论(0)