Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Advanced IntelliJ IDEA Configuration Guide for Java Development

Tech May 9 4

Project Environment Setup

Establishing a consistent development environment is the first step towards efficiency.

Code and File Encodings

Configure global encoding settings to prevent issues with international characters.

  1. Navigate to FileSettingsEditorFile Encodings.
  2. Set Global Encoding, Project Encoding, and Default encoding for properties files all to UTF-8.

JDK Configuration

Ensure the correct Java version is applied at both the project and compiler levels:

  1. Global SDK: Go to FileProject StructureSDKs. Select the path to your installed JDK.
  2. Project Default: Under Other SettingsDefault Project Structure, define the default JDK for new projects.
  3. Compiler Specifics: In Build, Execution, DeploymentCompilerJava Compiler, set the target bytecode level and source compatibility.

Build Tools Integration

Maven

Locate the Maven installation directory in FileSettingsBuild, Execution, DeploymentMaven to ensure the plugin utilizes the local binary rather then the bundled version.

Git

Map the Git executable location explicitly:

  • Path: FileSettingsVersion ControlGit.
  • Action: Browse to git.exe (e.g., C:/Program Files/Git/bin/git.exe).

Editor Optimization

Intelligent Comment Templates

Automating documentation creation saves significant time.

Class Header Template

Create a file template via EditorFile and Code TemplatesIncludesFile Header.

/**
 * @Title: ${PROJECT_NAME}
 * @Description: System Module Entry
 * @Version: 1.0.0
 * @Since: jdk1.8
 * @author ${USER}
 * @date ${DATE} ${TIME}
 */

Live Templates for Methods

Define custom abbreviations under Live Templates:

  • Group: DevTemplates
  • Abbreviation: m1 (for class comments) or m2 (for method comments).
  • Pattern:
/**
 * @Author $author$
 * @Description $description$
 * @Date $date$
 * @Param $param$
 * @return $return$
 */

Set expansion trigger to Enter and define variables like $date$ and $time$ to auto-populate dynamic values.

Workflow Efficiency

Shortcuts Reference

Adapting keybindings can drastically improve speed compared to other IDEs.

Task Shortcut
Find Class Ctrl + N
Search Files (Content) Ctrl + Shift + N
Generate Getter/Setter Alt + Insert
Format Code Ctrl + Alt + L
Refactor Rename Shift + F6
Quick Documentation Ctrl + Q
Show UML Diagram Ctrl + Alt + U
Toggle Column Mode Ctrl + Shift + I
Jump to Source Line Ctrl + G

Note: Keymaps might conflict with system input methods. If Ctrl + Space fails for completion, adjust KeymapCode Completion settings.

Navigation Enhancements

  • Line Numbers: Enable via EditorGeneralAppearanceShow line numbers.
  • Modified Tabs: Visual indicator for unsaved changes under EditorEditor TabsMark modified tabs with asterisk.
  • Quick Documentation: Enable hover tooltips by checking EditorGeneralShow quick documentation on mouse move.

External Tool Access

  • SSH Session: Use ToolsTerminalOpen SSH Session for remote command execution.
  • SFTP: Configure under SettingsBuild, Execution, DeploymentDeployment. Enter host details to manage remote resources directly from the IDE sidebar.
  • Configuration Backup: Export settings using FileExport Settings to generate a .jar backup, facilitating easy migration across machines.

Automation and Plugins

Recommended Extensions

Utilizing community plugins extends native functionality.

Plugin Purpose
Lombok Reduce boilerplate code (Getters, Setters).
SonarLint Real-time static code analysis.
Key Promoter Learn shortcuts by showing alternatives when menu navigation is used.
SequenceDiagram Visualize method call chains automatically.
EasyCode Database entity generation based on table structures.
Translation Built-in translation tool for documentation comments.

Automated Code Generation with EasyCode

This plugin allows generating standard layer structures (DAO, VO, Service, Controller) from database tables.

Installation

Access SettingsPlugins, search EasyCode, and install. Restart the IDE after completion.

Template Configuration

Customize output logic using Velocity templates. The following examples demonstrate how to configure specific layers.

Model Layer

Generates Entity classes mapped to DB columns.

/**
 * @Title: $!{tableInfo.comment}
 * @author $author
 * @date $!time.currTime()
 */
@Data
@Table(name = "$tableInfo.obj.name")
public class $!{tableInfo.name} implements Serializable {
#foreach($column in $tableInfo.fullColumn)
    #if(${column.comment})/** ${column.comment} */#end
    @Column(name = "$column.obj.name")
    private $!{tool.getClsNameByFullName($column.type)} $!{column.name};
#end
}

Service Implementation

Handles business logic delegation to DAO layers.

@Service("${tool.firstLowerCase($!{tableInfo.name})}Service")
public class $!{tableName} implements I$!{tableInfo.name}Service {
    @Resource
    private $!{tableInfo.name}Dao $!tool.firstLowerCase($!{tableInfo.name})Dao;

    @Override
    public boolean deleteById($!pk.shortType $!pk.name) {
        return this.$!{tool.firstLowerCase($!{tableInfo.name})}Dao.deleteById($!pk.name) > 0;
    }
}

Controller Layer

Exposes REST endpoints.

@RestController
@RequestMapping("/${tool.firstLowerCase($tableInfo.name)}")
public class $!{tableName} {
    @Autowired
    private I$!{tableInfo.name}Service service;

    @PostMapping(value = "save")
    public ApiResult insert(@RequestBody $!{tableInfo.name}VO vo) {
        return ApiResult.success(service.insert(vo));
    }
}

Generation Workflow

  1. Open the Database panel and connect to your data source.
  2. Right-click a specific table.
  3. Select EasyCodeGenerate Code.
  4. Choose the desired template group and destination package.
  5. Click OK to generate the source files automatically.

Troubleshooting Common Issues

Compilation Version Mismatch

If you encounter Error: java: invalid source release: 11, verify the Project Structure settings align with the installed JDK version (FileProject StructureSDK & Language Level).

Command Line Length Limitation

Windows environments often limit command string length. To bypass this:

  1. Locate workspace.xml in the .idea directory of your project root.
  2. Modify the <component name="PropertiesComponent"> tag.
  3. Add dynamic.classpath property: <property name="dynamic.classpath" value="true" />.

Cursor Input State Glitches

If the cursor behaves unexpectedly (Insert mode), check active plugins. If IdeaVim is enabled, disable it temporarily in SettingsPlugins to revert to standard editing behavior.

Unresolved Dependencies

For Spring context injection errors (like MyBatis Mapper failing): Ensure @MapperScan is correctly configured in the main application context or annotated packages match the generated mapper locations.

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.