Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run/Debug ElasticSearch in IntelliJ

Is there a way to debug ElasticSearch server in realtime from IntelliJ? I don't have any exp with Maven. My goal is to have it running while I can debug it and inspect variables and the execution flow.

like image 287
Vame Avatar asked Apr 16 '14 12:04

Vame


People also ask

How do I run debug mode in IntelliJ?

Run the program in debug modeClick the Run icon in the gutter, then select Modify Run Configuration. Enter arguments in the Program arguments field. Click the Run button near the main method. From the menu, select Debug.

Why Debug is not working in IntelliJ?

To solve this, simply remove the jar of the debugged module from all modules' dependencies in the Project Structure. If you do not know which modules have the debugged module jar as dependencies, you can use some tools (Eg. Sublime Text, bash, ...) to search for the module name which is stored in Intellij *.


2 Answers

Ok found it. Use the Run menu of IntelliJ to add a new run configuration.

  • Run
  • Edit configurations
  • +
  • Set Main class to org.elasticsearch.bootstrap.Bootstrap
  • Set VM options to -Des.foreground=yes

Voila. Credits.

like image 94
Vame Avatar answered Oct 21 '22 14:10

Vame


You have not indicated if you are asking to debug / step-into the Elastic Search (ES) client or sever code.

For Client Code

As long as the sources are attached, yes you can debug it. If you are using Maven, you can ask it to download (and attach) the sources assuming they are available in the Maven Central Repository. (Elastic Search does deploy its sources to maven central, so you should be good there. If not, you would have to "manually" attach the source jar in the Project Structure dialog.)

To get maven to download and attach, open the maven tool window and click the "Download..." button enter image description here and select either Download Sources or Download Sources and Documentation. IDEA will now download and attach all the available source (and/or javadoc) JARs for all the dependencies/libraries in your project. If desired, you can configure maven to always do this. To set it for the current project, click the settings button enter image description here in the maven tool window ans select the Importing node, or go to Settings > [Project Settings] > Maven > Importing. In the dialog, check the "Automatically Download" Sources and/or Documentation options. To set this as the default for all future projects you create, go to File > Other Settings > Default Settings > Maven > Importing and make the setting.

Once the sources are attached, you will be able to step into the elastic search code, or open one a class by either 1) using Ctrl+N to search for and enter a class, typing Ctrl+N a second time to include library classes in your search or 2) using Ctrl+B (when your cursor is on a method call) or Ctrl+Click to go to the method declaration. You can then set breakpoints.

For Server Code

You will need to create an elastic search project with the source code. The easiest thing would be to clone their repo (or otherwise check it out). You could also just attach the ES server libraries (including sources) to your project.

If you are running elastic search locally, just create a local Run/Debug configuration to run ES and launch via Debug. If running ES on a remote server, you will need to create a remote debug configuration and then attach to the remote ES server (which will need to be started with the proper Java Debug properties.) See Help > IntelliJ IDEA > Reference > Dialog > Run/Debug Configurations > Run/Debug Configuration: Remote and Help > IntelliJ IDEA > Language and Framework-Specific Guidelines > Java EE > Working with Application Servers > Working with Server Run/Debug Configurations for more information.

like image 26
Javaru Avatar answered Oct 21 '22 14:10

Javaru