I'm currently working on a Java project that is emitting the following warning when I compile:
/src/com/myco/apps/AppDBCore.java:439: warning: unmappable character for encoding UTF8
[javac] String copyright = "? 2003-2008 My Company. All rights reserved.";
I'm not sure how SO will render the character before the date, but it should be a copyright symbol, and is displayed in the warning as a question mark in a diamond.
It's worth noting that the character appears in the output artifact correctly, but the warnings are a nuisance and the file containing this class may one day be touched by a text editor that saves the encoding incorrectly...
How can I inject this character into the "copyright" string so that the compiler is happy, and the symbol is preserved in the file without potential re-encoding issues?
Try with: javac -encoding ISO-8859-1 file_name.java
This helped for me:
All you need to do, is to specify a envirnoment variable called JAVA_TOOL_OPTIONS. If you set this variable to -Dfile.encoding=UTF8, everytime a JVM is started, it will pick up this information.
If you're using Maven, set the <encoding>
explicitly in the compiler plugin's configuration, e.g.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
This worked for me -
<?xml version="1.0" encoding="utf-8" ?>
<project name="test" default="compile">
<target name="compile">
<javac srcdir="src" destdir="classes"
encoding="iso-8859-1" debug="true" />
</target>
</project>
If you use eclipse (Eclipse can put utf8 code for you even you write utf8 character. You will see normal utf8 character when you programming but background will be utf8 code) ;
P.S : this will ok if you static value in code. For Example String test = "IIIIIiiiiiiççççç";
If you are using Gradle then you can find the line that applies the java plugin:
apply plugin: 'java'
Then set the encoding for the compile task to be UTF-8:
compileJava {options.encoding = "UTF-8"}
If you have unit tests, then you probably want to compile those with UTF-8 too:
compileTestJava {options.encoding = "UTF-8"}
This means that the overall gradle code would look something like this:
apply plugin: 'java'
compileJava {options.encoding = "UTF-8"}
compileTestJava {options.encoding = "UTF-8"}
put this line in yor file .gradle above the Java conf.
apply plugin: 'java'
compileJava {options.encoding = "UTF-8"}
If you are using Gradle then you can find the line that applies the java plugin:
apply plugin: 'java'
Then set the encoding for the compile task to be UTF-8:
compileJava {options.encoding = "UTF-8"}
If you have unit tests, then you probably want to compile those with UTF-8 too:
compileTestJava {options.encoding = "UTF-8"}
This means that the overall gradle code would look something like this:
apply plugin: 'java'
compileJava {options.encoding = "UTF-8"}
compileTestJava {options.encoding = "UTF-8"}
If one is using Maven Build from the command prompt one can use the following command as well:
mvn -Dproject.build.sourceEncoding=UTF-8
For those wondering why this happens on some systems and not on others (with the same source, build parameters, and so on), check your LANG
environment variable. I get the warning/error when LANG=C.UTF-8
, but not when LANG=en_US.UTF-8
.
This worked for me -
<?xml version="1.0" encoding="utf-8" ?>
<project name="test" default="compile">
<target name="compile">
<javac srcdir="src" destdir="classes"
encoding="iso-8859-1" debug="true" />
</target>
</project>
If one is using Maven Build from the command prompt one can use the following command as well:
mvn -Dproject.build.sourceEncoding=UTF-8
Try with: javac -encoding ISO-8859-1 file_name.java
For those wondering why this happens on some systems and not on others (with the same source, build parameters, and so on), check your LANG
environment variable. I get the warning/error when LANG=C.UTF-8
, but not when LANG=en_US.UTF-8
.
This helped for me:
All you need to do, is to specify a envirnoment variable called JAVA_TOOL_OPTIONS. If you set this variable to -Dfile.encoding=UTF8, everytime a JVM is started, it will pick up this information.
If you're using Maven, set the <encoding>
explicitly in the compiler plugin's configuration, e.g.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Most of the time this compile error comes when unicode(UTF-8 encoded) file compiling
javac -encoding UTF-8 HelloWorld.java
and also You can add this compile option to your IDE
ex: Intellij idea
(File>settings>Java Compiler) add as additional command line parameter
-encoding : encoding Set the source file encoding name, such as EUC-JP and UTF-8.. If -encoding is not specified, the platform default converter is used. (DOC)
Most of the time this compile error comes when unicode(UTF-8 encoded) file compiling
javac -encoding UTF-8 HelloWorld.java
and also You can add this compile option to your IDE
ex: Intellij idea
(File>settings>Java Compiler) add as additional command line parameter
-encoding : encoding Set the source file encoding name, such as EUC-JP and UTF-8.. If -encoding is not specified, the platform default converter is used. (DOC)
If you use eclipse (Eclipse can put utf8 code for you even you write utf8 character. You will see normal utf8 character when you programming but background will be utf8 code) ;
P.S : this will ok if you static value in code. For Example String test = "IIIIIiiiiiiççççç";
I had the same problem, where the character index reported in the java error message was incorrect. I narrowed it down to the double quote characters just prior to the reported position being hex 094 (cancel instead of quote, but represented as a quote) instead of hex 022. As soon as I swapped for the hex 022 variant all was fine.
put this line in yor file .gradle above the Java conf.
apply plugin: 'java'
compileJava {options.encoding = "UTF-8"}
I had the same problem, where the character index reported in the java error message was incorrect. I narrowed it down to the double quote characters just prior to the reported position being hex 094 (cancel instead of quote, but represented as a quote) instead of hex 022. As soon as I swapped for the hex 022 variant all was fine.
Source: Stackoverflow.com