How to configure Character Encoding in Maven

Sometimes, java files compiling with maven or building war file get encoding error as described below.

  • File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
  • maven character encoding source not working

maven read the source code for building and installing artifacts, So It should define the character encoding to read and write files of different encoding types- ASCII, UTF-8 or UTF-16 maven uses default encoding of running platform, i.e ISO-8859-1.

Character encoding maven

This post helps developer to solve maven character encoding issues.

There are multiple ways we can configure encoding in maven projects.

You can check my other posts on maven commands

Configure character encoding at application

You can define properties project.reporting.outputEncoding in pom.xml to have encoding set at application level.


The advantages with this approach is, You need not define encoding manually for each plugin that you use.

Once this encoding is defined, all the plugins will reuse this configuration

Change encode to UTF-8 in maven resource plugin

resource plugin encoding can be fixed by configure below property


Or you can also add to UTF-8 in property.

Configure Command line maven options

It is required to run maven goals via command line, So We have to use either -D option or MAVEN_OPTS environment variable.

maven with -D options used to set environment variables, We can use encoding related properties as described below.



set "MAVEN_OPTS=-Duser.language=fr -Dfile.encoding=UTF-8"
set MAVEN_OPTS= -Dfile.encoding=UTF-8

encoding in maven compiler plugin

Compiler plugin is a plugin used to compile java source files, That means if any characters present in source files, you might get encoding issues.

Below is the way we can set character encoding to UTF-8 in maven compiler plugin


How to change encoding for maven test ?

when you are compiling and testing your java classes, You might get encoding issues for a line of code that has UTF-8 characters.

Maven tests are run with maven sure fire plugin, So you have to configure the plugin with configuration option - argLine.

This enables sure fire plugin to read all files with UTF-8 encoding



As we discussed above, Changing character encoding from default to UTF-8 involves global level, plugin or command line level, and also please update maven standard properties like Dfile.encoding, or project.reporting.outputEncoding in different ways.

I hope you liked this post:-) and please share it.

Join 6,000 subscribers and get a daily digest of full stack tutorials delivered to your inbox directly.No spam ever. Unsubscribe any time.

Similar Posts
You'll get a notification every time a post gets published here.