Organize java file import using eclipse from command line

I want to format java code and organize imports in a pre-commit hook using the command line. When I was looking for how to do this, I found a link

p>

which explains how to format the code using eclipse from the command line as follows:

eclipse -application org.eclipse.jdt.core.JavaCodeFormatter -config {setting}/org.eclipse.jdt.core.prefs {project.basedir}/src 

But I could not know the name of the parameter that is responsible for formatting the code, since I expect the command to look like this:

 eclipse -application {Java_Import_Organizer_Parameter} -config {setting}/org.eclipse.jdt.ui.prefs {project.basedir}/src 

any idea?

+7
java command-line eclipse import pre-commit-hook
source share
1 answer

Google Style Styleatter provides the ability to correct imports:

 $ java -jar google-java-format-1.4-all-deps.jar no files were provided Usage: google-java-format [options] file(s) Options: -i, -r, -replace, --replace Send formatted output back to files, not stdout. - Format stdin -> stdout --aosp, -aosp, -a Use AOSP style instead of Google Style (4-space indentation) --fix-imports-only Fix import order and remove any unused imports, but do no other formatting. --skip-sorting-imports Do not fix the import order. Unused imports will still be removed. --skip-removing-unused-imports Do not remove unused imports. Imports will still be sorted. --length, -length Character length to format. --lines, -lines, --line, -line Line range(s) to format, like 5:10 (1-based; default is all). --offset, -offset Character offset to format (0-based; default is all). --help, -help, -h Print this usage statement --version, -version, -v Print the version. If -i is given with -, the result is sent to stdout. The --lines, --offset, and --length flags may be given more than once. The --offset and --length flags must be given an equal number of times. If --lines, --offset, or --length are given, only one file (or -) may be given. google-java-format: Version 1.0 https://github.com/google/google-java-format 
0
source share

All Articles