Note that there are some explanatory texts on larger screens.

plurals
  1. POMVN compile not using UTF-8 encoding
    text
    copied!<p>Ok, this is a weird problem: I have a java test file that uses some UTF-8 characters. When I compile it with Maven, using</p> <pre><code>mvn -Dfile.encoding=UTF-8 -Dproject.build.sourceEncoding=UTF-8 test </code></pre> <p>(thus setting both the perceived platform encoding and the source file encoding, see <a href="https://stackoverflow.com/questions/9976616/maven-platform-encoding">maven platform encoding</a>) I get something like</p> <pre><code>[INFO] Scanning for projects... [INFO] ------------------------------------------------------------------------ [INFO] Building project [INFO] task-segment: [test] [INFO] ------------------------------------------------------------------------ [INFO] [resources:resources {execution: default-resources}] [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory path/src/main/resources [INFO] [compiler:compile {execution: default-compile}] [INFO] Nothing to compile - all classes are up to date [INFO] [resources:testResources {execution: default-testResources}] [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] skip non existing resourceDirectory path/src/test/resources [INFO] [compiler:testCompile {execution: default-testCompile}] [INFO] Compiling 7 source files to path/target/test-classes [INFO] ------------------------------------------------------------------------ [ERROR] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Compilation failure path/to/file.java:[42,23] unclosed character literal path/to/file.java:[42,25] ';' expected path/to/file.java:[42,26] unclosed character literal path/to/file.java:[47,23] unclosed character literal path/to/file.java:[47,25] illegal character: \182 path/to/file.java:[47,26] unclosed character literal </code></pre> <p>When I compile the file with </p> <pre><code>javac path/to/file.java </code></pre> <p>I get similar errors: </p> <pre><code>path/to/file.java:42: unclosed character literal illegalCharEnc('ä'); ^ path/to/file.java:42: ';' expected illegalCharEnc('ä'); ^ path/to/file.java:42: unclosed character literal illegalCharEnc('ä'); ^ path/to/file.java:47: unclosed character literal illegalCharDec('ö'); ^ path/to/file.java:47: illegal character: \182 illegalCharDec('ö'); ^ path/to/file.java:47: unclosed character literal illegalCharDec('ö'); ^ 6 errors </code></pre> <p>Now when I use </p> <pre><code>javac -encoding UTF-8 path/to/file.java </code></pre> <p>instead, I get <code>cannot find symbol</code> errors, because of the missing dependencies. So I figure the problem is that <code>javac</code> is not called with UTF-8 option in Maven when compiling tests (notice how <code>Using 'UTF-8' encoding to copy filtered resources.</code> is missing in <code>compiler:testCompile</code>-section). Is this conclusion correct? Am I missing something? Is this a known problem? Anything I can do about it? Obviously, the platform encoding on my system is not UTF-8, but I currently cannot change that.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload