I am compiling a package using maven and it says build failure with following compilation error:
SpanishTest.java[31, 81] unmappable character for encoding UTF8
I searched online and for many people, changing source encoding from UTF-8 to ISO-8859-1 seems to work but I am still getting same compilation error. I am using 32-bit Ubuntu. Here is how that tag looks in my pom.xml
<project.build.sourceEncoding>ISO-8859-1</project.build.sourceEncoding>
Even if I change <project.build.outputEncoding>
tag to ISO-8859-1, I still get the error.Could it be because of java version? I have both-sun java and openjdk installed on my system.
Can anyone please let me know what to do.
Thanks
This question is related to
java
maven
character-encoding
Set incodign attribute in maven-compiler plugin work for me. The code example is the following
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
I came across this problem just now and ended up resolving it like so: I opened up the offending .java file in Notepad++ and from the Encoding menu I selected "Convert to UTF-8 without BOM". Saved. Re-ran maven, all went through ok.
If the offending resource was not encoded in UTF-8 - as you have configured for your maven compiler plugin - you would see in the Encoding menu of Np++ a bullet mark next to the file's current encoding (in my case I saw it was set to "Encode in ANSI").
So your maven compiler plugin invoked the Java compiler with the -encoding option set to UTF-8, but the compiler encountered a ANSI-encoded source file and reported this as an error. This used to be a warning previously in Java 5 but is treated as an error in Java 6+
I too faced a similar issue and my resolution was different. I went to the line of code mentioned and traversed to the character (For SpanishTest.java[31, 81], go to 31st line and 81th character including spaces). I observed an apostrophe in comment which was causing the issue. Though not a mistake, the maven compiler reports issue and in my case it was possible to remove maven's 'illegal' character.. lol.
This happens in the following scenario: When working on Windows, the IDE is more than likely configured to edit files in Cp1252, which is a Microsoft adaptation of latin-11. The developer checks in, and the Continuous Integration server (usually running on Linux, which nowadays is all utf8) picks up the file, and tries to compile as a UTF-8 file, hence the warning.
Try changing the encoding to cp1252. This works. To avoid future problems of this kind, use the same encoding on all the developer machines.
Good luck...
When i inspect the console i found that the version of maven compiler is 2.5.1 but in other side i try to build my project with maven 3.2.2.So after writting the exact version in pom.xml, it works good. Here is the full tag:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
....
<configuration>
</plugin>
If the above answer does not work, change the encoding to cp1252 or manually remove all occurrences of the special character. For me ? special character was causing the prob which was inside a comment block.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>Cp1252</encoding>
</configuration>
</plugin>
PS:I was using GNU/Linux OS(Ubuntu).
I guess the issues happens at the encode strings. I solved same issues. Please try adding trim() at last of the encode string.
In my case I resolved that problem using such approach:
JAVA_TOOL_OPTIONS = -Dfile.encoding=UTF8
MAVEN_OPTS= -Dfile.encoding=UTF-8
Source: Stackoverflow.com