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.
- Select Run > Edit Configurations
- Select Add (+) option > Remote
- Configure Remote Settings, set the appropriate host/port configuration for your running tomcat or cli host location and provide an appropriate name (DSpace Remote)
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
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