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

2

6

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 across an issue with the oceanlink code, and wanted to debug, but had to resort to println / log info to see variables.

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

I was just wondering if there was more condensed, recent guidance on the subject.

Laodicean answered 19/9, 2014 at 15:44 Comment(2)
Just to ensure that I understand the question: are you already running maven, ant and Tomcat from within IDEA? If you're starting and stopping Tomcat in IntelliJ, entering debug mode just means hitting the start-debug button instead of the regular start button for tomcat.Atheism
Not running any of it within IDEA. The basic setup is only to use IDEA to view and change code. After changing code I redeploy manually: mvn package, ant update, tomcat restart. While attempting to follow the IntelliJ guide, it mentions to deploy an artifact, I don't know what to put in there. (Deployment tab of Tomcat Server configuration).Laodicean
A
6

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

Near the end of the video it shows which modules to deploy and how you can arrange the context paths.

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

One super powerful feature not covered in the video is "evaluate expression". When the program is paused in a breakpoint, you can use "evaluate expression" to execute any arbitrary method calls on the current state of the program.

Atheism answered 4/10, 2014 at 19:41 Comment(0)
D
3

Bram has provided an excellent tutorial on this topic, the one other strategy I can recommend that can sometimes be faster to setup is Remote Debugging.

The goal is to get into a "remote debug mode" on your existing deployed DSpace webapp in tomcat or in the DSpace CLI. Then you can attach to it directly without configuring embedded tomcat in Intellij. This is great because it can be completed locally using localhost or remotely over the network against an existing development server hostname/IP.

  1. Select Run > Edit Configurations
  2. Select Add (+) option > Remote
  3. Configure Remote Settings, set the appropriate host/port configuration for your running tomcat or cli host location and provide an appropriate name (DSpace Remote)
  4. Copy first text boxes settings into env settings to your tomcat or CLI instance.

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

    4.a. For DSpace CLI in [DSACE_HOME]/bin/dspace add the following line just prior to the java command (note we set suspend to y to assure that we have an opportunity to connect to the debugging port before the application executes.

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

    4.b For Tomcat Configuration export env settings already provided in tomcat catalina.sh script to start tomcat in debug mode. (note we set suspend to n to allow tomcat to start properly.

    export JPDA_OPTS=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005
    %TOMCAT_HOME%/bin/catalina.sh jpda start
    
  5. Once you have started the CLI app or Tomcat, then you can connect your configured debug settings. First select your Debug config from the Run/Debug dropdown on the toolbar and start in debug mode using the "Debug" icon.

This will connect to the debug port (if you have problems check for firewall restrictions). You should now be able to set breakpoints and step through your code in Intellij while it is executing on the server.

Caveats are that you will need to complete the entire mvn build/ant deploy to get any of your changes into the running tomcat/cli application. For faster developer turnaround, it is best to run the war/cli directly in intellij and using Bram's tutorial is excellent for that purpose. However, when this is not possible, this is a great alternative to be able to debug on existing live test sites.

Cheers, Mark

Diplomatics answered 5/10, 2014 at 20:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.