title: Is there a command line or Maven plugin to optimize/organize Java imports?
body: <p>There are plugins to format code using the Eclipse formatter from Maven, and its not hard to find instructions to run it from the command line. However, this formatter does not organize/optimize the import statements.</p>
  
  <p>The reason I want to do this is that I have generated some code, using a single pass over a template. It would be complex to work out up front what imports are needed and what are not, so I end up importing a lot of stuff that ends up not being used. A formatter that cleans up unused imports afterwards would solve the problem neatly.</p>
  
  <p>Specifically, I want to remove unused imports automatically, but not from within the IDE. How can I do this?</p>