文章

cursor java开发配置

cursor java开发配置

cursor java开发配置

常用插件

  • Extension Pack for Java:java开发全家桶,多个插件的合集。
  • Spring Boot Extension Pack: spring开发全家桶,多个插件的合集。
  • IntelliJ IDEA Keybindings:在Cursor中使用IDEA快捷键。

全局配置

在Cursor中配置环境需要写入settings.json文件中,settings.json文件有3个级别,配置分了3个级别:默认配置、全局用户配置、工作空间配置。

全局配置入口在File->Preference->Profile->Setting,将打开配置文件,所有在界面做的配置,都会写入到该文件。

配置文件参考,调整几个路径即可。

完整配置 ```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.configuration.updateBuildConfiguration": "automatic", "java.debug.settings.console": "internalConsole", "debug.console.fontSize": 14, "debug.console.fontFamily": "Consolas, 'Courier New', monospace", // java 格式化配置 start // ===== 缩进配置 ===== "editor.tabSize": 4, "editor.insertSpaces": true, "editor.detectIndentation": false, // ===== 单行最大长度 ===== "editor.rulers": [ 120 ], "editor.wordWrap": "wordWrapColumn", "editor.wordWrapColumn": 120, // ===== 保存时自动操作 ===== "editor.formatOnSave": true, "editor.formatOnPaste": true, "files.trimTrailingWhitespace": true, "files.insertFinalNewline": true, "files.autoSave": "afterDelay", "files.autoSaveDelay": 1000, // ===== Java 特定格式化 ===== "java.format.enabled": true, "java.format.onType.enabled": true, // "java.format.settings.profile": "GoogleStyle", // 插件市场没有p3c插件,本地配置仍然能使用部分功能,缺少规范自动检查和提示 // "java.format.settings.url": "https://raw.githubusercontent.com/alibaba/p3c/master/p3c-formatter/eclipse-codestyle.xml", // 在线配置方式 "java.format.settings.url": "file:///D:/p3c-formatter/eclipse-codestyle.xml", "java.format.settings.profile": "P3C", // ===== 导入优化 ===== "java.saveActions.organizeImports": true, "java.completion.importOrder": [ "java", "javax", "com", "org" ], // ===== 代码检查 ===== "java.compile.nullAnalysis.mode": "automatic", // 启用增量编译 "java.errors.incompleteClasspath.severity": "warning", // ===== 编辑器增强 ===== "editor.bracketPairColorization.enabled": true, "editor.renderWhitespace": "boundary", "editor.renderLineHighlight": "all", // ===== 文件排除 ===== "search.exclude": { "**/target": true, "**/build": true, "**/.gradle": true, "**/out": true, "**/bin": true } // java 格式化配置 end } ```

常见问题和解决

窗口内整合多个工程

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

maven打包插件报错

  • 工程pom文件报错 Failed to execute mojo org.apache.maven.plugins:maven-dependency-plugin:3.7.0:copy-dependencies {execution: copy-dependencies}
  • 解决方案 插件兼容性问题,新增maven配置文件
  • 配置路径urlcursor://settings/java.configuration.maven.lifecycleMappings 文件名vscode-maven-lifecycle-mappings-metadata.xml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    
      <?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>
    
本文由作者按照 CC BY 4.0 进行授权