简体   繁体   English

从命令行传递Maven编译器选项

[英]Passing Maven Compiler Options From The Command-line

I am setting up several projects on a continuous integration server, some of which I don't have access to change the source code to, The server is a linux box, I am running into a problem where maven encoding needs to be changed to UTF8 to be able to compile on the box. 我在一个持续集成服务器上设置了几个项目,其中一些我没有权限将源代码更改为,服务器是一个linux盒子,我遇到了一个需要将maven编码更改为UTF8的问题能够在盒子上编译。 Since I don't have access to modify the pom file, I was wondering if I can pass the compiler options as a command-line param? 由于我无权修改pom文件,我想知道我是否可以将编译器选项作为命令行参数传递? The project uses maven compiler 2.0 and I tried passing -Denconding=UTF8 without success. 该项目使用maven编译器2.0,我尝试传递-Denconding = UTF8但没有成功。

You can use the Maven property "project.build.sourceEncoding". 您可以使用Maven属性“project.build.sourceEncoding”。

So something along the lines of mvn clean install -Dproject.build.sourceEncoding=UTF-8 should accomplish what you need. 所以mvn clean install -Dproject.build.sourceEncoding=UTF-8应该mvn clean install -Dproject.build.sourceEncoding=UTF-8您的需求。

This is equivalent of 这相当于

<properties>
   <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

in your pom.xml. 在你的pom.xml中。

Edit: As a point of reference, there is the following link available POM Element for Source File Encoding showing the nuances between these properties for both Maven 2.0 and 3.0 编辑:作为参考点, 有源链接文件编码的以下链接可用POM元素显示Maven 2.0和3.0的这些属性之间的细微差别

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM