A formatter for Java files that uses the Prettier formatter.
Install via the VS Code marketplace.
For one time use:-
- Open the Command Palette (ctrl+shift+p).
- Select 'Format Document With...' or 'Format Document' if this formatter is the only Java formatter installed.
- Select 'Java prettier formatter'.
To set as default formatter for Java files:-
- Open the Command Palette (ctrl+shift+p).
- Select 'Preferences: Configure Language Specific Settings'.
- Select 'Java'.
- Add
"editor.defaultFormatter": "mwpb.java-prettier-formatter"
into the [java]
section.
Then the formatter should be available with Alt+Shift+f
on windows and `Ctrl+Shift+i1 on Linux.
Place a .prettierrc
in your workspace.
(Or alternatively an appropriate .editorconfig
.)
Changes require restart to take effect.
npm i -g vsce
vsce package
vsce publish
This package completes the 'last yard' to use Prettier with Java files in VS Code in a standalone way. The hard work and credit is due to:-
- Prettier - Formatter.
- Prettier plugin Java - Java specific formatting.