使用eclipse从命令行组织java文件的导入

使用eclipse从命令行组织java文件的导入,java,eclipse,command-line,import,pre-commit-hook,Java,Eclipse,Command Line,Import,Pre Commit Hook,我想格式化java代码,并使用命令行在预提交钩子中组织导入,当我搜索如何执行此操作时,我发现 这说明了如何从命令行使用eclipse格式化代码,如下所示: eclipse -application org.eclipse.jdt.core.JavaCodeFormatter -config {setting}/org.eclipse.jdt.core.prefs {project.basedir}/src 但无法知道负责格式化代码的参数名称,因为我希望命令如下所示: eclipse -appl

我想格式化java代码,并使用命令行在预提交钩子中组织导入,当我搜索如何执行此操作时,我发现

这说明了如何从命令行使用eclipse格式化代码,如下所示:

eclipse -application org.eclipse.jdt.core.JavaCodeFormatter -config {setting}/org.eclipse.jdt.core.prefs {project.basedir}/src
但无法知道负责格式化代码的参数名称,因为我希望命令如下所示:

eclipse -application {Java_Import_Organizer_Parameter} -config {setting}/org.eclipse.jdt.ui.prefs {project.basedir}/src
有什么想法吗?

提供了修复导入的选项:

$ 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

Java开发工具提供的唯一命令行应用程序是JavaCodeFormatter和JavaIndexer;但是看起来似乎没有办法从命令行组织导入。这并没有重现Eclipse添加缺少的导入的功能(怎么可能,它会问你想要哪个类)。它们很好地隐藏了这个选项。谢谢你发布它们。