reformat java code
I was working with a project that was saved in linux I opened it in a windows IDE and the strange thing is that it inserted break lines in all .java .jsp and other te开发者_如何学编程xt files
I like to remove all those empty lines recursively at the root directory of the project.
Does anybody have some shell script that can I run to change these files?
Thanks in advance, André.
You might just need to run dos2unix on the files. Pass it through a hex viewer to see if the line-endings are 0D 0A
(CR/LF) or are actually two newlines or something else. If the former, dos2unix will work. Something like:
find . -name \*.java -exec dos2unix \{\} \;
From your root source directory. Test first, make backups, etc.
Which Windows IDE are you using? Is this Eclipse? If yes.
Window -> Preferences -> Java -> Code Style -> Clean Up -> Edit -> Remove Trailing whitespace
Hopefully this will work
On a sidenote, not directly being an answer to your question (it seems like there already are good answers), I would recommend, if possible, to use a bit of time to uniformly setup your IDE environments so that they are compatible.
I have great experience in using Eclipse as it is available for all major OS platforms, and has the option of saving essential project settings in whichever repository you are using, thus enabling you to have identical setups so that for example line breaks are handled properly.
Also, to ensure everybody has the same Eclipse configuration, plugin versions, even basic workspace configurations, I strongly recommend using Eclipse configuration management tools like Yoxos, as it enables you to specifically configure a Eclipse configuration per project, and distribute said configuration in a simple XML-based file associated with the Yoxos Launcher program which handles dependencies, updates etc.
I have been involved in quite a few projects thus far, and even in teams where we are developing from Linux, Windows and Mac OS X, there are no (or well as minimal as possible anyway) problems with configurations, line breaks, plugin versions, etc. due to the extra effort in streamlining the IDE setups.
You might want to see if you can configure your IDE/editor to deal with the files instead of converting them. If you use source control, changing all your line endings will flag every line in every file as "modified", and that will make it difficult (if not impossible) to track changes if/when you migrate the code back to your Linux system.
精彩评论