We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

Ant don't treat UTF-8 files as UTF-8 when compiling

Geronimooo
Geronimooo asked
on
Medium Priority
5,286 Views
Last Modified: 2013-11-10
I have a strange problem. I'm Swedish and we have special characters å ä ö in our alphabet.
In my project all my java-files are encoded as UTF-8. When I compile my project inside intellij my text-strings apperas correct in the console and in my swing-app.

However when I run my build script in Ant it creates strange characters instead of å ä ö.

If I put the text-strings in a propertiefile everything works well even with an ant-compile.

<property name="compile.debug" value="true"/>
    <property name="compile.deprecation" value="true"/>
    <property name="compile.optimize" value="true"/>
 
 
        <javac srcdir="${src.dir}" destdir="${build.home}"
               debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}">
            <classpath refid="libs"/>
            <classpath location="${build.home}"/>
            <include name="**/*.java"/>
            <exclude name="**/StartJetty6.java"/>
        </javac>

Open in new window

Comment
Watch Question

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
> However when I run my build script in Ant it creates strange characters instead of å ä ö.

creates them where?

Author

Commented:
Same as when I compile it in Intellij, in the console and in my swing-app when I run my app...
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
sounds like it just that the console (and/or the font it uses) that you are viewing it doesn't support utf8 swedish characters.

Author

Commented:
Nope.... As I wrote.. if I compile the project inside intellij and then run it.. everything looks as it should..
compile the same project with ant does not give the same result...

In both cases I'm looking at text printed in my Swing-app.

Running the project inside intellij with ant-build generated class files will give the same problem. Recompiling inside intellij and everything works..
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
try:

ant -Dfile.encoding=UTF8 build

Author

Commented:
tried that same problem...
downloaded ant 1.7.1 and tried as well..

Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
no idea sorry, thats a weird one

solved it. You could add UTF-8 at the compiler in ant.

See below code
        <javac srcdir="${src.dir}" destdir="${build.home}"
               debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}" encoding="UTF-8">
            <classpath refid="libs"/>
            <classpath location="${build.home}"/>
            <include name="**/*.java"/>
            <exclude name="**/StartJetty6.java"/>
        </javac>

Open in new window

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Mick BarryJava Developer
CERTIFIED EXPERT
Top Expert 2010

Commented:
good work :)

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.