In DSpace, how do I debug live code using IntelliJ IDEA?

My current development process is to change Java code, mvn package, ant update, restart my tomcat server. I would really like to be able to add breakpoints and debug my DSpace instance live. I recently ran into a problem with ocean communication code and wanted to debug, but I had to resort to println / log information to view variables.

I am familiar with the wiki page: https://wiki.duraspace.org/display/DSPACE/IDE+Integration+-+DSpace+and+IDEA

I'm just wondering if there was a more concise, recent guide to this.

+5
source share
2 answers

I created a video walkthrough describing our developer installation in IDEA: https://www.youtube.com/watch?v=mrLl1qPsy6I

At the end of the video, which modules you need to deploy and how you can organize context paths are shown.

Less than two years after the previous video, here is finally the debug video: https://www.youtube.com/watch?v=V5Zi71zYmf8

One super-powerful feature not covered in the video is the โ€œexpression of appreciation." When a program is stopped at a breakpoint, you can use the expression "expression" to make any calls to arbitrary methods in the current state of the program.

+5
source

Bram has provided an excellent tutorial on this topic, another strategy that I can recommend, which can sometimes be faster to set up, is remote debugging.

The goal is to enter "remote debugging mode" on an existing deployed DSpace web server in tomcat or in CLS DSpace. Then you can connect directly to it without setting up the built-in tomcat in Intellij. This is great because it can be executed locally using localhost or remotely over the network against the existing host name / IP address of the development server.

  • Choose Run> Modify Configurations.
  • Select the Add (+)> Remote option.
  • Configure remote settings, configure the appropriate host / port configuration for your tomcat or cli host site and provide the appropriate name (DSpace Remote)
  • Copy the first settings of the text fields into the env settings on your tomcat or CLI instance.

    -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 

    4.a. For the DSpace CLI in [DSACE_HOME] / bin / dspace, add the following line immediately before the java command (note that we set suspend to y to ensure that we can connect to the debug port before the application executes.

     export JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005" 

    4.b For configuration, Tomcat Configurations are already provided in the tomcat catalina.sh script to run tomcat in debug mode. (note that we set suspend to n to allow tomcat to start correctly.

     export JPDA_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005 %TOMCAT_HOME%/bin/catalina.sh jpda start 
  • Once you have launched the CLI or Tomcat application, you can enable the customized debugging settings. First, select the Debug configuration from the Run / Debug drop-down list on the toolbar and start in debug mode using the Debug icon.

This will result in a connection to the debug port (if you have problems checking the limits of the firewall). Now you can set breakpoints and execute your code in Intellij while it is running on the server.

The caveats are that you will need to complete the deployment of mvn build / ant in order to get any changes in the current tomcat / cli application. To speed up development, it is best to run war / cli directly in intellij, and using a Bram tutorial is great for this purpose. However, when this is not possible, this is a great alternative to debug existing test sites.

Cheers, Mark

+3
source

Source: https://habr.com/ru/post/1202983/


All Articles