51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1899|回复: 2
打印 上一主题 下一主题

[原创] Maven中指定Java的编译版本和源文件编码方式

[复制链接]
  • TA的每日心情
    无聊
    2024-3-7 09:16
  • 签到天数: 43 天

    连续签到: 2 天

    [LV.5]测试团长

    跳转到指定楼层
    1#
    发表于 2019-2-18 16:05:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

    使用Maven编译Java项目,默认的编译版本是1.5.

    参考官网的说明-》https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html

    source
    String
    2.0

    The -source argument for the Java compiler.

    Default value is: 1.5.

    User property is: maven.compiler.source.

    target
    String
    2.1
    The -encoding argument for the Java compiler.
    Default value is: ${project.build.sourceEncoding}.
    User property is: encoding.
    encoding
    String
    2.0

    The -target argument for the Java compiler.

    Default value is: 1.5.

    User property is: maven.compiler.target.


    如果要指定Java编译版本有两种方式

    1)在settings.xml中指定,例如

    1. <profiles>      
    2.     <profile>  
    3.         <id>JDK1.7</id>  
    4.         <activation>  
    5.             <activeByDefault>true</activeByDefault>  
    6.         </activation>  
    7.         <properties>  
    8.             <maven.compiler.source>1.7</maven.compiler.source>  
    9.             <maven.compiler.target>1.7</maven.compiler.target>  
    10.             <encoding>UTF-8</encoding>  
    11.         </properties>  
    12.     </profile>  
    13. </profiles>
    复制代码

    2)在pom.xml中指定,例如

    1. <build>  
    2.     <plugins>  
    3.         <plugin>  
    4.             <groupId>org.apache.maven.plugins</groupId>  
    5.             <artifactId>maven-compiler-plugin</artifactId>  
    6.             <version>${maven-compiler-plugin.version}</version>  
    7.             <configuration>  
    8.                 <source>1.7</source>  
    9.                 <target>1.7</target>  
    10.                 <encoding>UTF-8</encoding>  
    11.             </configuration>  
    12.         </plugin>  
    13.     </plugins>  
    14. </build>  
    复制代码


    分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    本版积分规则

    关闭

    站长推荐上一条 /1 下一条

    小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

    GMT+8, 2024-4-20 22:57 , Processed in 0.063872 second(s), 23 queries .

    Powered by Discuz! X3.2

    © 2001-2024 Comsenz Inc.

    快速回复 返回顶部 返回列表