{"id":13861939,"url":"https://github.com/emacs-lsp/lsp-java","last_synced_at":"2025-07-14T09:34:22.521Z","repository":{"id":38290057,"uuid":"88609809","full_name":"emacs-lsp/lsp-java","owner":"emacs-lsp","description":"lsp-mode :heart: java","archived":false,"fork":false,"pushed_at":"2024-03-28T08:16:58.000Z","size":3216,"stargazers_count":626,"open_issues_count":111,"forks_count":83,"subscribers_count":29,"default_branch":"master","last_synced_at":"2024-05-01T11:36:37.054Z","etag":null,"topics":["emacs","emacs-lsp","java","jdt-server","lsp","lsp-java","spring-boot","spring-initializr"],"latest_commit_sha":null,"homepage":"https://emacs-lsp.github.io/lsp-java","language":"Emacs Lisp","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/emacs-lsp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-04-18T09:55:39.000Z","updated_at":"2024-05-01T11:36:37.054Z","dependencies_parsed_at":"2023-12-30T21:01:00.072Z","dependency_job_id":"eeeb50cf-7aaf-410f-b4f4-db0058b58320","html_url":"https://github.com/emacs-lsp/lsp-java","commit_stats":{"total_commits":297,"total_committers":50,"mean_commits":5.94,"dds":0.3535353535353535,"last_synced_commit":"9296ecd97310458d39338566c3491a27d90f5577"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emacs-lsp%2Flsp-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emacs-lsp%2Flsp-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emacs-lsp%2Flsp-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emacs-lsp%2Flsp-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emacs-lsp","download_url":"https://codeload.github.com/emacs-lsp/lsp-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225968892,"owners_count":17553157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["emacs","emacs-lsp","java","jdt-server","lsp","lsp-java","spring-boot","spring-initializr"],"created_at":"2024-08-05T06:01:33.345Z","updated_at":"2024-11-22T21:31:23.599Z","avatar_url":"https://github.com/emacs-lsp.png","language":"Emacs Lisp","readme":"[![MELPA](https://melpa.org/packages/lsp-java-badge.svg)](https://melpa.org/#/lsp-java)\n[![MELPA Stable](https://stable.melpa.org/packages/lsp-java-badge.svg)](https://stable.melpa.org/#/lsp-java)\n[![Build Status](https://github.com/emacs-lsp/lsp-java/workflows/CI/badge.svg?branch=master)](https://github.com/emacs-lsp/lsp-java/actions)\n[![Join the chat at https://gitter.im/emacs-lsp/lsp-mode](https://badges.gitter.im/emacs-lsp/lsp-mode.svg)](https://gitter.im/emacs-lsp/lsp-mode?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\nlsp-java\n========\n\nEmacs Java IDE using [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls).\n\n## Requirements\n- JDK 17\n\n## Features\nLSP java mode supports the following JDT Features:\n\n* As you type reporting of parsing and compilation errors (via [flycheck](https://github.com/flycheck/flycheck)/[lsp-ui](https://github.com/emacs-lsp/lsp-ui))\n* Code completion - using [company-capf](https://github.com/company-mode/company-mode) or builtin ```complete-at-point```\n* Javadoc hovers - using [lsp-ui](https://github.com/emacs-lsp/lsp-ui)\n* Code actions - using [lsp-ui](https://github.com/emacs-lsp/lsp-ui)\n* Code outline - using builtin [imenu](https://www.gnu.org/software/emacs/manual/html_node/emacs/Imenu.html)\n* Code navigation - using builtin [xref](https://www.gnu.org/software/emacs/manual/html_node/emacs/Xref.html)\n* Code lens (references/implementations) - using builtin [xref](https://www.gnu.org/software/emacs/manual/html_node/emacs/Xref.html)\n* Highlights\n* Code formatting\n* Maven pom.xml project support\n* Limited Gradle support\n* Visual debugger - [dap-mode](https://github.com/yyoncho/dap-mode/)\n* Test runner - [dap-mode](https://github.com/yyoncho/dap-mode/)\n* Project explorer integration - [treemacs](https://github.com/Alexander-Miller/treemacs)\n* Integration with [Spring Initializr](https://start.spring.io/)\n## Demo\nHere it is a demo from EmacsConf2019 https://www.youtube.com/watch?v=Bbjxn9yVNJ8\n## Tutorial\nHere is a tutorial that covers setup and use https://xpressrazor.wordpress.com/2020/11/04/java-programming-in-emacs/\n## Screenshot\n![demo](images/demo.png)\n## Installation\n### Spacemacs\n[lsp-java](https://github.com/emacs-lsp/lsp-java) is included in spacemacs (for now only on the dev branch). If you are using the development version of\nspacemacs you can simply add `(java :variables java-backend 'lsp)` to `dotspacemacs-configuration-layers`.\n\n### Install via melpa\nThe recommended way to install LSP Java is via `package.el` - the built-in package\nmanager in Emacs. LSP Java is available on the two major `package.el` community\nmaintained repos - [MELPA Stable](http://stable.melpa.org) and [MELPA](http://melpa.org).\n\n\u003ckbd\u003eM-x\u003c/kbd\u003e `package-install` \u003ckbd\u003e[RET]\u003c/kbd\u003e `lsp-java` \u003ckbd\u003e[RET]\u003c/kbd\u003e\n\nThen add the following lines to your `.emacs` and open a file from the any of the specified projects.\n```emacs-lisp\n(require 'lsp-java)\n(add-hook 'java-mode-hook #'lsp)\n```\n### [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls)\n\n[lsp-java](https://github.com/emacs-lsp/lsp-java) will automatically detect when the server is missing and it will download [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) before the first startup. The server installation will be in `lsp-java-server-install-dir`. It will detect whether [dap-mode](https://github.com/yyoncho/dap-mode/) is present and it will download the required server side plugins/components. If you want to update the server you can run `lsp-java-update-server`. To run specific version of [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) use `lsp-java-server-install-dir`.\n\n### Quick start\nMinimal configuration with [company-capf](https://github.com/company-mode/company-mode) and [lsp-ui](https://github.com/emacs-lsp/lsp-ui) and [dap-mode](https://github.com/yyoncho/dap-mode/). Set `lsp-java-workspace-dir` in case you have existing Java projects. Now you can explore the methods under `lsp-java-*`, `dap-java-*`, `dap-*`, and `lsp-*`.\n\n```elisp\n(condition-case nil\n    (require 'use-package)\n  (file-error\n   (require 'package)\n   (add-to-list 'package-archives '(\"melpa\" . \"http://melpa.org/packages/\"))\n   (package-initialize)\n   (package-refresh-contents)\n   (package-install 'use-package)\n   (setq use-package-always-ensure t)\n   (require 'use-package)))\n\n(use-package projectile)\n(use-package flycheck)\n(use-package yasnippet :config (yas-global-mode))\n(use-package lsp-mode :hook ((lsp-mode . lsp-enable-which-key-integration)))\n(use-package hydra)\n(use-package company)\n(use-package lsp-ui)\n(use-package which-key :config (which-key-mode))\n(use-package lsp-java :config (add-hook 'java-mode-hook 'lsp))\n(use-package dap-mode :after lsp-mode :config (dap-auto-configure-mode))\n(use-package dap-java :ensure nil)\n(use-package helm-lsp)\n(use-package helm\n  :config (helm-mode))\n(use-package lsp-treemacs)\n```\n## Supported commands\n### LSP Mode commands\n* `lsp-execute-code-action` - Execute code action.\n* `lsp-rename` - Rename symbol at point\n* `lsp-describe-thing-at-point` - Display help for the thing at point.\n* `lsp-goto-type-definition` - Go to type definition\n* `lsp-goto-implementation` - Go to implementation\n* `lsp-restart-workspace` - Restart project\n* `lsp-format-buffer` - Format current buffer\n* `lsp-symbol-highlight` - Highlight all relevant references to the symbol under point.\n* `lsp-workspace-folders-add` - Add workspace folder\n* `lsp-workspace-folders-remove` - Remove workspace folder\n* `lsp-workspace-folders-switch` - Switch workspace folder\n### LSP Java commands\n* `lsp-java-organize-imports` - Organize imports\n* `lsp-java-build-project` - Perform partial or full build for the projects\n* `lsp-java-update-project-configuration` - Update project configuration\n* `lsp-java-actionable-notifications` - Resolve actionable notifications\n* `lsp-java-update-user-settings` - Update user settings (Check the options in the table bellow.)\n* `lsp-java-update-server` - Update server instalation.\n* `lsp-java-generate-to-string` - Generate `toString` method.\n* `lsp-java-generate-equals-and-hash-code` - Generate `equals` and `hashCode` methods.\n* `lsp-java-generate-overrides` - Generate method `overrides`\n* `lsp-java-generate-getters-and-setters` - Generate getters and setters.\n* `lsp-java-type-hierarchy` - Open type hierarchy. Use prefix arg to specify the type of the hierarchy.\n#### Refactoring\nLSP Java provides rich set of refactorings via [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) code actions and\nsome of them are bound to Emacs commands:\n\n* `lsp-java-extract-to-constant` - Extract constant refactoring\n* `lsp-java-add-unimplemented-methods` - Extract constant refactoring\n* `lsp-java-create-parameter` - Create parameter refactoring\n* `lsp-java-create-field` - Create field refactoring\n* `lsp-java-create-local` - Create local refactoring\n* `lsp-java-extract-method` - Extract method refactoring\n* `lsp-java-add-import` - Add missing import\n#### Testing support\n* `lsp-jt-browser` - Browse tests and run/debug them.\n** Use `x` to run the test(s) under point; `d` to debug the tests under point. `R` to refresh.\n** Support for GUI operations.\n* `lsp-jt-report-open` - open test report\n* `lsp-jt-lens-mode` - test lenses mode(requires `lsp-lens-mode` to be enabled.)\n\n#### Dependency viewer\n* `lsp-java-dependency-list` - View java dependencies\n\n#### STS4 Integration (experimental)\n\nLSP java has integration with [STS4](https://github.com/spring-projects/sts4/) providing the following functionality.\n\n## Spring boot support (Experimental)\n\nIn addition to the integration with [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) [lsp-java](http://github.com/emacs-lsp/lsp-java) provides integration with [STS4](https://github.com/spring-projects/sts4/)  which covers Spring Boot\n`application.properties`, `application.yml` and `.java` files.\n\n## Usage:\nMake sure that you have configured `JAVA_HOME`. `lsp-java` will automatically download the [STS4](https://github.com/spring-projects/sts4/) when you call `lsp-java-update-server`. In order to enable [STS4](https://github.com/spring-projects/sts4/)  integration add the following lines to your config:\n``` emacs-lisp\n(require 'lsp-java-boot)\n\n;; to enable the lenses\n(add-hook 'lsp-mode-hook #'lsp-lens-mode)\n(add-hook 'java-mode-hook #'lsp-java-boot-lens-mode)\n```\n\n## Functionality for `.java`\n\n### Navigating the source code - Go to symbol in file/workspace\nEasy navigation to Spring-specific elements of your source code.\n\n![Go to Symbol in workspace](images/java-navigation.png)\n\n#### Commands\n`lsp-workspace-symbol` - (works better usign [helm-lsp](https://github.com/yyoncho/helm-lsp))\n\n#### Examples\n* `@/` shows all defined request mappings (mapped path, request method, source location)\n* `@+` shows all defined beans (bean name, bean type, source location)\n* `@\u003e` shows all functions (prototype implementation)\n* `@` shows all Spring annotations in the code\n\n### Quick-access for running apps\nEasy navigation to the provided request mappings of running apps.\n\n![accessing running apps quickly](images/running-apps.png)\n\n#### Commands\n`lsp-workspace-symbol` - (works better usign [helm-lsp](https://github.com/yyoncho/helm-lsp))\n\n#### Examples\n* `//` shows all request mappings of all running Spring Boot apps and opens a browser for the selected endpoint\n\n### Live application information hovers\nSTS4 automatically detects JVM processes for running boot applications on your local machine.\n\nFor some types of information, STS 4 may also show a 'quick summary' as a codelens.\n\nIf there are multiple instances of the app running on your machine, the live data from all those instances will show up in the hover information.\n\n``` emacs-lisp\n(add-hook 'java-mode-hook #'lsp-java-boot-lens-mode)\n```\n![live data from running apps as hover on source code](images/live-hovers.png)\n\n#### Examples\n* `@Profile`: shows information about the active profiles on the running apps\n* `@Component`, `@Bean`, `@Autowired`: shows detailed information about the beans and their wiring from the live app\n* `@ContidionalOn...`: shows information about the conditions and their evaluation at runtime\n\n### Code templates\nWrite Spring code with templates, available via regular code completion.\n\n#### Examples\n* `@GetMapping`\n* `@PostMapping`\n* `@PutMapping`\n\n### Smart code completions\nAdditional code completions for Spring-specific annotations\n\n![Smart code completion for boot properties](images/validation-completion.png)\n\n## Functionality for `.properties` and `.yml`\n\nThis extension analyzes your project's classpath and parses and indexes any [Spring Boot\nProperties Metadata](https://docs.spring.io/spring-boot/docs/current/reference/html/configuration-metadata.html) it finds. Both Maven and Gradle projects are supported.\n\nThe data in the index is used to provide validation, code completions and information\nhovers while editing Spring Boot Properties in either `.properties` or `.yml` format.\n\n### Validation and code completion in properties file\n![application-properties-validation](images/validation-completion.png)\n\n### Validation and code completion in yaml file\n![application-properties-validation](images/yaml-completion-and-help.png)\n\n#### Spring Initializr\n`lsp-java` provides a frontend for [Spring Initializr](https://start.spring.io/) which simplifies the creation of Spring Boot projects directly from Emacs via `lsp-java-spring-initializr`.\n![Create Spring boot project](images/boot.png)\n## Supported settings\n* `lsp-java-server-install-dir` -\n  \"Install directory for eclipse.jdt.ls-server.\nThe slash is expected at the end.\"\n* `lsp-java-jdt-download-url` - JDT JS download url.\nUse http://download.eclipse.org/che/che-ls-jdt/snapshots/che-jdt-language-server-latest.tar.gz if you want to use Eclipse Che JDT LS.\n* `lsp-java-java-path` - Path of the java executable.\n* `lsp-java-progress-string` - Java progress status as reported by the language server.\n* `lsp-java-workspace-dir` - LSP java workspace directory.\n* `lsp-java-workspace-cache-dir` - LSP java workspace cache directory.\n* `lsp-java-themes-directory` - Directory containing themes.\n* `lsp-java-theme` - Theme to use.\n* `lsp-java-pop-buffer-function` - The function which will be used for showing the helper windows.\n* `lsp-java-vmargs` - Specifies extra VM arguments used to launch the Java Language Server. Eg. use `-noverify -Xmx1G -XX:+UseG1GC -XX:+UseStringDeduplication` to bypass class verification,increase the heap size to 1GB and enable String deduplication with the G1 Garbage collector\n* `lsp-java-9-args` - Specifies arguments specific to java 9 and later.\n* `lsp-java-errors-incomplete-classpath-severity` - Specifies the severity of the message when the classpath is incomplete for a Java file\n* `lsp-java-configuration-check-project-settings-exclusions` - Checks if the extension-generated project settings files (.project, .classpath, .factorypath, .settings/) should be excluded from the file explorer.\n* `lsp-java-configuration-update-build-configuration` - Specifies how modifications on build files update the Java classpath/configuration\n* `lsp-java-trace-server` - Traces the communication between VS Code and the Java language server.\n* `lsp-java-import-gradle-enabled` - Enable/disable the Gradle importer.\n* `lsp-java-import-maven-enabled` - Enable/disable the Maven importer.\n* `lsp-java-maven-download-sources` - Enable/disable eager download of Maven source artifacts.\n* `lsp-java-references-code-lens-enabled` - Enable/disable the references code lens.\n* `lsp-java-signature-help-enabled` - Enable/disable the signature help.\n* `lsp-java-implementations-code-lens-enabled` - Enable/disable the implementations code lens.\n* `lsp-java-configuration-maven-user-settings` - Path to Maven's settings.xml\n* `lsp-java-format-enabled` - Enable/disable default Java formatter\n* `lsp-java-save-actions-organize-imports ` - Enable/disable auto organize imports on save action\n* `lsp-java-import-exclusions` - Configure glob patterns for excluding folders\n* `lsp-java-content-provider-preferred` - Preferred content provider (a 3rd party decompiler id, usually). We support https://github.com/dgileadi/vscode-java-decompiler. To enable it, add:\n    ```elisp\n    (setq lsp-java-content-provider-preferred \"fernflower\")\n    ```\n* `lsp-java-autobuild-enabled` - Enable/disable the 'auto build'\n* `lsp-java-max-concurrent-builds` - Max simultaneous project builds\n* `lsp-java-completion-enabled` - Enable/disable code completion support\n* `lsp-java-completion-overwrite` - When set to true, code completion overwrites the current text. When set to false, code is simply added instead.\n* `lsp-java-completion-guess-method-arguments` - When set to true, method arguments are guessed when a method is selected from as list of code assist proposals.\n* `lsp-java-completion-favorite-static-members` - Defines a list of static members or types with static members. Content assist will propose those static members even if the import is missing.\n* `lsp-java-completion-import-order` - Defines the sorting order of import statements. A package or type name prefix (e.g. 'org.eclipse') is a valid entry. An import is always added to the most specific group.\n* `lsp-java-folding-range-enabled` - Enable/disable smart folding range support. If disabled, it will use the default indentation-based folding range provided by VS Code.\n* `indentation-based` - [Experimental] Enable/disable progress reports from background processes on the server.\n* `lsp-java-progress-reports-enabled` - [Experimental] Enable/disable progress reports from background processes on the server.\n* `lsp-java-format-settings-url` - Specifies the url or file path to the [Eclipse formatter xml settings](https://github.com/redhat-developer/vscode-java/wiki/Formatter-settings).\n* `lsp-java-format-settings-profile` - Optional formatter profile name from the Eclipse formatter settings.\n* `lsp-java-format-comments-enabled` - Includes the comments during code formatting.\n* `lsp-java-format-on-type-enabled` - Enable/disable automatic block formatting when typing `;`, `\u003center\u003e` or `}`\n* `lsp-java-bundles` - List of bundles that will be loaded in the JDT server.\n* `lsp-java-code-generation-hash-code-equals-use-java7objects` - Use Objects.hash and Objects.equals when generating the hashCode and equals methods. This setting only applies to Java 7 and higher.\n* `lsp-java-code-generation-hash-code-equals-use-instanceof` - Use 'instanceof' to compare types when generating the hashCode and equals methods.\n* `lsp-java-code-generation-use-blocks` - Use blocks in 'if' statements when generating the methods.\n* `lsp-java-code-generation-generate-comments` - Generate method comments when generating the methods.\n* `lsp-java-code-generation-to-string-template` - The template for generating the toString method.\n* `lsp-java-code-generation-to-string-code-style` - The code style for generating the toString method.\n* `lsp-java-code-generation-to-string-skip-null-values` - Skip null values when generating the toString method.\n* `lsp-java-code-generation-to-string-list-array-contents` - List contents of arrays instead of using native toString().\n* `lsp-java-code-generation-to-string-limit-elements` - Limit number of items in arrays/collections/maps to list, if 0 then list all.\n* `lsp-java-inhibit-message` - If non-nil, inhibit java messages echo via `inhibit-message'.\n\n## Additional packages\n* [lsp-ui](https://github.com/emacs-lsp/lsp-ui) : Flycheck, documentation and code actions support.\n* [company-capf](https://github.com/company-mode/company-mode) : Company backend support.\n* [treemacs](https://github.com/Alexander-Miller/treemacs) : Project viewer.\n* [lsp-treemacs](https://github.com/emacs-lsp/lsp-treemacs) : `lsp-mode` GUI controls implemented using treemacs.\n## FAQ\n* LSP Java is showing to many debug messages, how to stop that?\nAdd the following configuration.\n```emacs-lisp\n(setq lsp-inhibit-message t)\n```\n* [lsp-ui](https://github.com/emacs-lsp/lsp-ui) does not display all of the actions on the current point(e. g \"Extract constant\")?\nLSP UI by default sends current line bounds for action region which breaks forces JDT server to return only \"Extract method action.\"\n```emacs-lisp\n(setq lsp-ui-sideline-update-mode 'point)\n```\n* LSP Java does not provide completion, go to definition for some of the files?\n\nWhen particular file is not part of imported project [Eclipse JDT Language Server](https://projects.eclipse.org/projects/eclipse.jdt.ls) could not calculate the current classpath.\n\n* How do I change the version of java used by LSP?\n\nHave a look at `~/.emacs.d/workspace/.metadata/.plugins/org.eclipse.jdt.launching/libraryInfos.xml`. If you updated your local java path and want LSP to use the new version, try removing the `~/.emacs.d/workspace/` directory and relaunch LSP. Also see [#114](https://github.com/emacs-lsp/lsp-java/issues/114).\nIf you have multiple java JDK versions installed and want to change the version of java used by LSP, also need to set `lsp-java-configuration-runtimes`. An example for setting `lsp-java-configuration-runtimes`:\n\n```lisp\n(setq lsp-java-configuration-runtimes '[(:name \"JavaSE-1.8\"\n\t\t\t\t\t\t:path \"/home/kyoncho/jdk1.8.0_201.jdk/\")\n\t\t\t\t\t(:name \"JavaSE-11\"\n\t\t\t\t\t\t:path \"/home/kyoncho/jdk-11.0.1.jdk/\"\n\t\t\t\t\t\t:default t)])\n```\n\n* How do I change JVM args passed to JDT server?\nLSP slowness could be caused by slow JDT server, especially on large JAVA projects. Bump up the heap size maybe a good idea.\n\n```lisp\n;; current VSCode defaults\n(setq lsp-java-vmargs '(\"-XX:+UseParallelGC\" \"-XX:GCTimeRatio=4\" \"-XX:AdaptiveSizePolicyWeight=90\" \"-Dsun.zip.disableMemoryMapping=true\" \"-Xmx2G\" \"-Xms100m\"))\n```\n","funding_links":[],"categories":["Emacs Lisp"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femacs-lsp%2Flsp-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femacs-lsp%2Flsp-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femacs-lsp%2Flsp-java/lists"}