Advanced IntelliJ IDEA Configuration Guide for Java Development
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.
- Navigate to
File→Settings→Editor→File Encodings. - 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:
- Global SDK: Go to
File→Project Structure→SDKs. Select the path to your installed JDK. - Project Default: Under
Other Settings→Default Project Structure, define the default JDK for new projects. - Compiler Specifics: In
Build, Execution, Deployment→Compiler→Java Compiler, set the target bytecode level and source compatibility.
Build Tools Integration
Maven
Locate the Maven installation directory in File → Settings → Build, Execution, Deployment → Maven to ensure the plugin utilizes the local binary rather then the bundled version.
Git
Map the Git executable location explicitly:
- Path:
File→Settings→Version Control→Git. - 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 Editor → File and Code Templates → Includes → File 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) orm2(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 + Spacefails for completion, adjustKeymap→Code Completionsettings.
Navigation Enhancements
- Line Numbers: Enable via
Editor→General→Appearance→Show line numbers. - Modified Tabs: Visual indicator for unsaved changes under
Editor→Editor Tabs→Mark modified tabs with asterisk. - Quick Documentation: Enable hover tooltips by checking
Editor→General→Show quick documentation on mouse move.
External Tool Access
- SSH Session: Use
Tools→Terminal→Open SSH Sessionfor remote command execution. - SFTP: Configure under
Settings→Build, Execution, Deployment→Deployment. Enter host details to manage remote resources directly from the IDE sidebar. - Configuration Backup: Export settings using
File→Export Settingsto generate a.jarbackup, 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 Settings → Plugins, 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
- Open the
Databasepanel and connect to your data source. - Right-click a specific table.
- Select
EasyCode→Generate Code. - Choose the desired template group and destination package.
- 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 (File → Project Structure → SDK & Language Level).
Command Line Length Limitation
Windows environments often limit command string length. To bypass this:
- Locate
workspace.xmlin the.ideadirectory of your project root. - Modify the
<component name="PropertiesComponent">tag. - Add
dynamic.classpathproperty:<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 Settings → Plugins 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.