Community
Participate
Working Groups
Created attachment 107182 [details] Runnable example and full source. Build ID: I20080617-2000 Steps to reproduce: 1. Start Eclipse 3.4 on Windows XP. 2. Check Eclipse configuration details: beside some other settings, file.encoding is set to Cp1252. 3. Create a new plug-in project "com.example.utf8" in workspace. 4. Set text file encoding for source files in this project to UTF-8. 5. Implement a BundleActivator which does the following: public void start() throws Exception { String data = "§"; System.out.println("data = "+data); System.out.println("data.length() = "+data.length() ); byte[] dataBytes = data.getBytes(); System.out.print("data.getBytes() = "); for (int i=0; i<dataBytes.length; i++) System.out.print(dataBytes[i]+" "); } 6. Execute the plug-in inside an OSGi framework run configuration in Eclipse. It prints: data = -º data.length() = 1 data.getBytes() = -62 -89 7. Export the bundle via "Export.. Deployable plug-ins and fragments". 8. Start Equinox framework with the exported bundle on a command shell: # java -Dfile.encoding=UTF-8 -Dosgi.bundles=com.example.utf8_1.0.0.jar@start -jar plugins/org.eclipse.osgi_3.4.0.v20080605-1900.jar It prints: data = +é-º data.length = 2 data.getBytes() = -61 -126 -62 -89 This output is wrong. The String has been enhanced by two bytes. The output should be the same as in in step 6. Workaround: 1. Close Eclipse. 2. Edit eclipse.ini. Add the following line after the parameter "-vmwargs": -Dfile.encoding=UTF-8 3. Start Eclipse. 4. Export the plug-in again. 5. Start Equinox framework with the exported bundle on a command shell. It prints: data.getBytes() = -62 -89 More information: The "Export.. Deployable plug-ins and fragments" function recompiles the source files in the project. If the eclipse file.encoding parameter is set to Cp1252, the String with the special character in the class file is enhanced by two bytes. This leads to the wrong output. If you compare both compiled class files you will see, that their is different by two bytes. When comparing both class files on hex basis, you can see, that this two bytes are added at the String definition. Running the code inside Eclipse always returns correct output.
"Deployable plug-ins and fragments" is provided by PDE. I thought you ment the JAR export wizard. Sorry for the confusion.
PDE Build isn't workspace aware. This is a dupe. A way to get encodings to work is to set something like this in your project build.properties... javacCustomEncodings.. = src/org/foo[US-ASCII],\ src/org/foo/bar.java[ISO-8859-1] *** This bug has been marked as a duplicate of bug 155015 ***