BAEL-4170 add Maven encoding examples (#12332)
* BAEL-4170 add Maven encoding examples * GTSIS-4170 update name of test class
This commit is contained in:
parent
34af11b770
commit
edc22b309a
@ -19,7 +19,7 @@
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>properties-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>generate-resources</phase>
|
||||
@ -32,12 +32,37 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<configuration>
|
||||
<!--encoding>UTF-8</encoding-->
|
||||
<!--propertiesEncoding>ISO-8859-1</propertiesEncoding-->
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<!--encoding>UTF-8</encoding-->
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<name>${project.name}</name>
|
||||
<my.awesome.property>property-from-pom</my.awesome.property>
|
||||
<!--these properties are normally set in the parent POM and would be overidden
|
||||
by the plugin specific properties above.-->
|
||||
<!--project.build.sourceEncoding></project.build.sourceEncoding-->
|
||||
<!--project.build.sourceEncoding>US-ASCII</project.build.sourceEncoding-->
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -0,0 +1,26 @@
|
||||
package com.baeldung.maven.properties;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/*
|
||||
* Simple class to demonstrate the importance of Maven encoding when dealing with NonAscii characters
|
||||
*/
|
||||
public class NonAsciiString {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NonAsciiString.class);
|
||||
|
||||
public static String getNonAsciiString() {
|
||||
|
||||
String nonAsciiStr = "ÜÝÞßàæç";
|
||||
LOGGER.info(nonAsciiStr);
|
||||
return nonAsciiStr;
|
||||
|
||||
/*We can even use non-ASCII characters as Java variables names.
|
||||
The below will run fine when built using Maven UTF-8 encoding,
|
||||
but not when using US-ASCII. Give it a go!*/
|
||||
/*String nonAsciiŞŧř = "ÜÝÞßàæç";
|
||||
LOGGER.info(nonAsciiŞŧř);
|
||||
return nonAsciiŞŧř;*/
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.baeldung.maven.properties;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class NonAsciiStringUnitTest {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NonAsciiStringUnitTest.class);
|
||||
|
||||
/**
|
||||
* Sanity check to ensure that the code is still able to compile and run
|
||||
*/
|
||||
@Test
|
||||
public void whenNonAsciiStringIsUsed_thenCodeRuns() {
|
||||
String nonAsciiStr = NonAsciiString.getNonAsciiString();
|
||||
LOGGER.info(nonAsciiStr);
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user