Friday, March 2, 2018

The way we can use 'intellij community edition' to debug tomcat application:

 Environment configurations use for this explanation:

        #  apache-tomcat-7.0.85
        #  IntelliJ IDEA 2017.3.2 (Community Edition)

Steps:

1. Build the project and put the war file into the webapps folder(<tomcat_home>/webapps/).

2. Intellij IDEA
    a) Run -> Edit Configurations
    b) Press the green + and select 'Remote'
    c) Give a proper name (Ex: debug-demo)
    d) Set the host and port(not the tomcat running port number. better to keep the default 5005)
    f) Select the 'Search sources using module's classpath (better to select root)
    g) Copy the 'Command line arguments for running remove JVM'
    Ex: -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005

3. Tomcat
    a) Open the 'setclasspath.sh'
    b) Set the above copied 'Command line arguments for running remove JVM' value to the  'JAVA_OPTS'. To do that, paste the below line at the end of the file:
JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
    c) Start the tomcat
        Ex: sh startup.sh

4. Intellij IDEA
    a) Select the 'debug-demo' according to our example
    b) Press 'Debug' icon (Shift+9)

Then you can see the connected message in the console as below:
Connected to the target VM, address: 'localhost:5005', transport: 'socket'

Enjoy...!!!

No comments:

Post a Comment