Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Eclipse formatter from the CLI and UTF-8(UTF-8 encoding destroyed)
Eclipse formatter from the CLI and UTF-8 [message #1830391] Fri, 24 July 2020 14:52 Go to next message
Walter Weinmann is currently offline Walter WeinmannFriend
Messages: 3
Registered: July 2009
Junior Member
My application generates Java program code that is UTF-8 encoded. The formatting of this generated program code is done with eclipsec and org.eclipse.jdt.core.JavaCodeFormatter. Unfortunately, after formatting, the code is destroyed, i.e. the UTF-8 encoding has disappeared. How can I prevent this. My command for formatting looks like this:

eclipsec -nosplash -data eclipse_workspace -application org.eclipse.jdt.core.JavaCodeFormatter -config src\main\resources\org.eclipse.jdt.core.prefs -quiet src\main\java\ch\konnexions\db_seeder\generated\
Re: Eclipse formatter from the CLI and UTF-8 [message #1830404 is a reply to message #1830391] Sat, 25 July 2020 05:59 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 31562
Registered: July 2009
Senior Member
I'm not sure it's the best or only way, but specifying a trailing "-vmargs -Dfile.encoding=UTF-8" should make that the default encoding of the JVM so maybe that works. Normally, in the IDE, the workspace preferences are used, so I'm not sure the state or contents of "eclipse_workspace"...

Perhaps the JDT folks have a better answer.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Eclipse formatter from the CLI and UTF-8 [message #1830420 is a reply to message #1830404] Sat, 25 July 2020 17:20 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 6880
Registered: July 2009
Senior Member
Hi

When what is 'read' is not what is 'written' you need to decide whether you have a bad writer, bad persistence or a bad reader. Corruption of non-ASCII characters is often the result of novice programming and a malconversion between bytes in a Stream and chars in a Writer. The Java formatter has been well used so it is likely to be ok. I suggest you use some neutral programs such as Notepad2 or the Eclipse Generic Text editor to see whether you have successfully written in a truly UTF-8 format; a neutral program should be able to detect the format from the preamble.(Tweaking the JVM may make the problem go away but it risks just deferring it until something else obscure occurs and may introduce a different problem for code that expects the regular default.)

Regards

Ed Willink
Re: Eclipse formatter from the CLI and UTF-8 [message #1830431 is a reply to message #1830404] Sun, 26 July 2020 06:21 Go to previous messageGo to next message
Walter Weinmann is currently offline Walter WeinmannFriend
Messages: 3
Registered: July 2009
Junior Member
Thank you very much - this was the solution.

eclipsec -nosplash -data eclipse_workspace -application org.eclipse.jdt.core.JavaCodeFormatter -config ...\org.eclipse.jdt.core.prefs -quiet <files> -vmargs -Dfile.encoding=UTF-8
Re: Eclipse formatter from the CLI and UTF-8 [message #1830432 is a reply to message #1830420] Sun, 26 July 2020 06:26 Go to previous message
Walter Weinmann is currently offline Walter WeinmannFriend
Messages: 3
Registered: July 2009
Junior Member
Ed Willink wrote on Sat, 25 July 2020 13:20
Hi

When what is 'read' is not what is 'written' you need to decide whether you have a bad writer, bad persistence or a bad reader. Corruption of non-ASCII characters is often the result of novice programming and a malconversion between bytes in a Stream and chars in a Writer. The Java formatter has been well used so it is likely to be ok. I suggest you use some neutral programs such as Notepad2 or the Eclipse Generic Text editor to see whether you have successfully written in a truly UTF-8 format; a neutral program should be able to detect the format from the preamble.(Tweaking the JVM may make the problem go away but it risks just deferring it until something else obscure occurs and may introduce a different problem for code that expects the regular default.)

Regards

Ed Willink


The program code in my application was generated with UTF-8 but the formatting changed the encoding. See attached files.
Previous Topic:I need a MIPs-enabled SWt.jar file
Next Topic:JDT core doesn't resolve constant for wrapper
Goto Forum:
  


Current Time: Sat Oct 31 14:31:05 GMT 2020

Powered by FUDForum. Page generated in 0.01499 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top