Output .js files from GWT in UTF-8 encoding with BOM

477 views Asked by At

I'm using the Javascript files outputted by GWT in a Windows 8.1 app, however as well as being UTF-8 encoded the files also need the Byte Order Mark at the start.

(See this question for why: http://social.msdn.microsoft.com/Forums/windowsapps/en-US/dd352270-8790-4b48-8492-17a4a6875e99/why-the-utf8-with-bom-marker-requirement )


Not sure if it's relevant, but I'm building GWT using Maven.

Is there anything I can change in the Maven pom.xml file that will output the files encoded in UTF-8 with the BOM?

Or a change to GWT config file?


Thank you for your help, I've been trying to figure this one out all afternoon!

1

There are 1 answers

0
Jon Cox On

Just in case anyone stumbles across this question in the future and wants an answer...

I couldn't find a way to do this with GWT, so I added some code to a .bat build script that runs.

Before running this script you will need to save an empty file (filewithbom.txt) that contains only the UTF-8 Byte Order Marker (0xEF 0xBB 0xBF if you're interested). This can be done by saving an empty file in Notepad, and being sure to set the encoding to UTF-8.

You will also want to change the CHANGE_DIR directory.

set OLD_DIR="%CD%"
set CHANGE_DIR="[PATH TO DIRECTORY WITH FILES TO CHANGE]"
set BOM_FILE="filewithbom.txt"
cd %CHANGE_DIR%
for /R %%f in (*.js, *.html) do (  
  type %BOM_FILE% >> tempfile.txt    
  type %%f >> tempfile.txt
  xcopy /Y tempfile.txt %%f
  del tempfile.txt
)
cd %OLD_DIR%

This loops through the CHANGE_DIR directory and it's subfolders, and adds the contents filewithbom.txt to the start of every file with a filename ending .js or .html.