Maven: codificação de origem no UTF-8 não está funcionando?
Eu estou convertendo um projeto de Ant para Maven e estou tendo problemas com um teste de unidade específico que lida com caracteres UTF-8. O problema é sobre a seguinte string:
String l_string = "ČäÁÓý\n€řЖжЦ\n№ЯФКЛ";
O problema é que o teste de unidade falha, porque o String é lido como o seguinte:
?äÁÓý
€????
?????
A classe java é salva como UTF-8 e também especifico a codificação de construção para UTF-8 no pom.xml.
Aqui está um trecho da minhapom.xml:
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.15</version>
</plugin>
</plugins>
</build>
Estou faltando alguma coisa aqui? Seria ótimo se alguém pudesse me ajudar aqui.
Atualizar
Em relação ao código de teste:
@Test
public void testTransformation()
{
String l_string = "ČäÁÓý\n€řЖжЦ\n№ЯФКЛ";
System.out.println( ">>> " + l_string );
c_log.info( l_string );
StringBuffer l_stringBuffer = new StringBuffer();
int l_stringLength = l_string.length();
String l_fileName = System.getProperty( "user.dir" ) + File.separator + "transformation" + File.separator + "TransformationMap.properties";
Transformation.init( l_fileName );
Properties l_props = Transformation.getProps();
for ( int i = 0; i < l_stringLength; i++ )
{
char l_char = l_string.charAt( i );
int l_intValue = (int) l_char;
if ( l_intValue <= 255 )
{
l_stringBuffer.append( l_char );
}
else
{
l_stringBuffer.append( l_props.getProperty( String.valueOf( l_char ), "" ) );
}
}
c_log.info( l_stringBuffer.toString() );
byte[] l_bytes = l_string.getBytes();
byte[] l_transformedBytes = Transformation.transform( l_bytes );
assertNotNull( l_transformedBytes );
}
A seguinte lógica não é realmente relevante (?) Porque após o primeiro sysout o "?" são impressos em vez dos caracteres corretos (e, portanto, os testes a seguir falham). Também não há uso de uma codificação de plataforma padrão.
O teste converte cada caractere de acordo com o arquivo TransformationMap.properties, que está no seguinte formato (apenas um trecho):
Ý=Y
ý=y
Ž=Z
ž=z
°=.
€=EUR
Deve-se notar que o teste é executado sem qualquer problema quando eu construir o projeto com Ant.