When developing Java with VS Code, it is useless if you do not set anything. There are many articles that only introduce Java to the point where it can be used even if you search on the net, so I would like to introduce the contents that should be set for those who want to develop Java in a strict manner.
-Java Extension Pack must be installed
There is an installer for developing Java with VS Code, but this is not enough. There are other useful ones, so I will introduce them.
Java IDE Java-related files such as Class and Interface are created with class definitions and packages defined.
Lombok Annotations Support for VS Code It is a plugin to support Lombok, which is familiar with automatic generation, with VS Code. VS Code will be able to recognize Lombok related annotations.
There is a place to specify Java formatter in VS Code, but you can specify URL or local file path. Since I want to customize this time, I will first create my own formatter. It is possible to create a definition file as a text file, but since there is also a preview on the GUI, I will use Eclipse this time.
(1) Start Eclipse and open [Preferences]. (2) Select [Java]-[Code Style]-[Formatter]. (3) Click the [New] button. (4) Enter an arbitrary name (here, "My Formatter") in [Profile name] and click the "OK" button. (5) Make the following format settings.
category | item | value |
---|---|---|
Indentation | Tab policy | spaces only |
Line Wrapping | Never join already wrapped lines | check |
(6) After completing the settings, click the "OK" button. (7) Select the one created above (MyFormatter) from [Active Profile] and click the [Export All] button to save it locally. The file name to save is "formatter.xml".
Open [Settings] and configure the following settings.
item | Set value |
---|---|
Editor: Detect Indentation | no check |
Editor: Format On Save | check |
Java › Format › Settings: Url | /path/to/formatter.xml |
Java › Format › Settings: Profile | MyFormatter |
Java › Save Actions: Organize Imports | check |
At a minimum, you have an environment where you can develop Java. If you have any other opinions that you should do this, I would appreciate it if you could let me know.
Recommended Posts