Cursor Java开发配置

Cursor Java开发配置


全文链接: Cursor Java开发配置


常用插件推荐

  1. Extension Pack for Java - Java开发全家桶,多个插件的合集
  2. Spring Boot Extension Pack - Spring开发全家桶,多个插件的合集
  3. IntelliJ IDEA Keybindings - 在Cursor中使用IDEA快捷键

配置详解

配置级别

Cursor的settings.json配置文件分为3个级别:

  • 默认配置 - 系统预设
  • 全局用户配置 - 用户级别设置
  • 工作空间配置 - 项目级别设置

配置入口

  • 路径:File -> Preference -> Profile -> Setting
  • 所有界面配置都会自动写入settings.json文件

完整配置示例

settings.json内容,只需调整本地路径。

json 复制代码
{
  "window.commandCenter": true,
  "workbench.colorTheme": "Visual Studio Light",
  "java.jdt.ls.java.home": "C:/Program Files/Java/jdk1.8.0_311",
  "maven.executable.path": "D:/apache-maven-3.9.9/bin/mvn.cmd",
  "[java]": {
    "editor.defaultFormatter": "redhat.java"
  },
  "java.configuration.maven.globalSettings": "D:\\apache-maven-3.9.9\\conf\\settings.xml",
  "files.encoding": "utf8",
  "terminal.integrated.defaultProfile.windows": "PowerShell",
  "terminal.integrated.profiles.windows": {
    "PowerShell": {
      "source": "PowerShell",
      "args": ["-NoLogo"],
      "icon": "terminal-powershell"
    }
  },
  "terminal.integrated.env.windows": {
    "LANG": "zh_CN.UTF-8"
  }
}
Java格式化配置
缩进配置
json 复制代码
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.detectIndentation": false
单行最大长度
json 复制代码
"editor.rulers": [120],
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 120
保存时自动操作
json 复制代码
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 1000
Java特定格式化
json 复制代码
"java.format.enabled": true,
"java.format.onType.enabled": true,
"java.format.settings.url": "file:///D:/p3c-formatter/eclipse-codestyle.xml",
"java.format.settings.profile": "P3C"
导入优化
json 复制代码
"java.saveActions.organizeImports": true,
"java.completion.importOrder": ["java", "javax", "com", "org"]
代码检查
json 复制代码
"java.compile.nullAnalysis.mode": "automatic",
"java.errors.incompleteClasspath.severity": "warning"
编辑器增强
json 复制代码
"editor.bracketPairColorization.enabled": true,
"editor.renderWhitespace": "boundary",
"editor.renderLineHighlight": "all"
文件排除
json 复制代码
"search.exclude": {
  "**/target": true,
  "**/build": true,
  "**/.gradle": true,
  "**/out": true,
  "**/bin": true
}

常见问题和解决方案

1. 窗口内整合多个工程

解决方案

  • 升级为工作空间:File -> Add Folder to WorkSpace...
  • 添加后点击Save保存工作空间
  • 会在当前目录下生成.code-workspace文件
  • 可以在Cursor内打开该文件,提供按钮触发切换为工作空间

2. Maven打包插件报错

问题:工程pom文件报错

复制代码
Failed to execute mojo org.apache.maven.plugins:maven-dependency-plugin:3.7.0:copy-dependencies {execution: copy-dependencies}

解决方案

  • 插件兼容性问题,需要新增maven配置文件
  • 配置路径:cursor://settings/java.configuration.maven.lifecycleMappings
  • 文件名:vscode-maven-lifecycle-mappings-metadata.xml

配置文件内容

xml 复制代码
<?xml version="1.0" encoding="UTF-8"?>
<lifecycleMappingMetadata>
    <pluginExecutions>
        <pluginExecution>
            <pluginExecutionFilter>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <versionRange>[2.10,)</versionRange>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
            </pluginExecutionFilter>
            <action>
                <ignore />
            </action>
        </pluginExecution>
    </pluginExecutions>
</lifecycleMappingMetadata>
相关推荐
77qqqiqi26 分钟前
解决忘记修改配置密码而无法连接nacos的问题
java·数据库·docker·微服务
ALLSectorSorft40 分钟前
相亲小程序用户注册与登录系统模块搭建
java·大数据·服务器·数据库·python
琢磨先生David1 小时前
Java 垃圾回收机制:自动化内存管理的艺术与科学
java
岁忧1 小时前
(nice!!!)(LeetCode 每日一题) 2561. 重排水果 (哈希表 + 贪心)
java·c++·算法·leetcode·go·散列表
阿华的代码王国2 小时前
【Android】RecyclerView实现新闻列表布局(1)适配器使用相关问题
android·xml·java·前端·后端
码农BookSea2 小时前
自研 DSL 神器:万字拆解 ANTLR 4 核心原理与高级应用
java·后端
lovebugs2 小时前
Java并发编程:深入理解volatile与指令重排
java·后端·面试
慕y2742 小时前
Java学习第九十一部分——OkHttp
java·开发语言·学习
caisexi2 小时前
Windows批量启动java服务bat脚本
java·windows·python
NullPointerExpection2 小时前
win10 环境删除文件提示文件被使用无法删除怎么办?
java·ide·windows·win10