Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong character encoding in dist jar generated with NetBeans

I finally wrote me little app. It's desktop app but it has embedded web server. When I lunched it from NetBeans everything is ok. When I lunch dist jar I have correct character encoding in GUI, but web server output is corrupted ("?" instead of national characters).

I use NetBeans 6.7.1, jdk1.6.0_16, http server from Java 6 SE and lib Rome 1.0

I don't put any source code here, because I have no idea witch part should I put.

//edit: data are hardcoded in Strings. Those Strings are passed to Rome as arguments to create RSS nodes, Romes RSS feeds are are written to String and then Strings are passed to HttpHandler.

like image 225
Maciek Sawicki Avatar asked Nov 16 '25 07:11

Maciek Sawicki


2 Answers

  • Check the encoding in the source files.
  • Check any point where encoding/decoding is performed (often any place where String -> byte[] or byte[] -> String). Anything that converts bytes to Strings is performing an encoding operation myEncoding -> UTF-16.
  • Check that you are passing the appropriate encoding information to 3rd party libraries that perform encoding/decoding.
  • If generating XML, ensure that the header encoding matches the encoding used to write the bytes (<?xml version="1.0" encoding="UTF-8"?>).
  • If serving content over HTTP, ensure that the content type and charset header is correct (e.g. Content-Type: text/html; charset=utf-8). A charset is usually only applicable if serving a text MIME type (it is not applicable for application/rss+xml, for example). Check your MIME documentation.
like image 118
McDowell Avatar answered Nov 18 '25 19:11

McDowell


This issue probably has nothing to do with NetBeans. Usually character encoding issues are due to not defining the character encoding somewhere, in which case the actual character encoding will be determined pretty much by luck.

For instance, Java Strings are UTF-16 internally, but the encoding used by Java Readers is determined by the platform default unless explicitly specified.

like image 30
Joonas Pulakka Avatar answered Nov 18 '25 21:11

Joonas Pulakka



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!