0

How can I pass encoding UTF-8 to the Javac compiler in maven? Here is my code:

Assert.assertTrue(CollectionWidjet.getColPickerListWrapperList(i).getListSpan().getText().trim().equalsIgnoreCase(data.getCollections().get(i).getName().trim()));

This is run over a list of input. Basically when it's a non-Unicode character like Hindi/Chinese it fails.

In normal javac compiler here is how it would get compiled:

javac -encoding UTF-8 MainClass.java
2
  • It's hard for us to interpret so much in one line of code. Could you please split it over multiple lines?
    – gparyani
    Commented Aug 11, 2013 at 19:49
  • The encoding used to compile the source code doesn't matter for the snippet you show.
    – Joni
    Commented Aug 11, 2013 at 20:02

1 Answer 1

3

Are you trying to change the encoding of the source or the default encoding to use when the program is run. It is not something set at compile time which then becomes the default at runtime.

If this makes such a difference I wouldn't use the default encoding, but always specify it in code.

In short, you can set the file encoding in maven using

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

And you can set it in your code using a Charset like StandardCharsets.UTF_8 (in Java 7)

You can set it on the command line using

 -Dfile.encoding=UTF-8

and this can be set using maven by setting the fork options http://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html

But it is better not to need this for your program to run correctly.

2
  • 1
    I'm sure that you know better than me, but shouldn't this be a comment?
    – Steve P.
    Commented Aug 11, 2013 at 19:53
  • 1
    @SteveP. +1 rephrased it to be more of an answer than a comment. Commented Aug 11, 2013 at 20:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.