Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't debug Java project in IDEA IntelliJ 12

On OSX w/Tomcat7 and IDEA IntelliJ 12.

The run configuration works fine. The debug configuration complains with:

    /usr/local/Cellar/tomcat/7.0.37/libexec/bin/catalina.sh run
    Error occurred during initialization of VM
    agent library failed to init: jdwp
    ERROR: Cannot load this JVM TI agent twice, check your java command line for duplicate jdwp options.
    Disconnected from server

I found this post from '11 but it's not helping.

The note about "once I removed it from system variables (inside the IDEA it is read only) problem was fixed" makes sense. So I tried removing this entire block from catalina.sh

    if [ -z "$JPDA_OPTS" ]; then
    JPDA_OPTS="-agentlib:jdwp=transport=$JPDA_TRANSPORT,address=$JPDA_ADDRESS,server=y,suspend=$JPDA_SUSPEND"
    fi

Didn't help. Any help would be greatly appreciated. Thanks!

java run command:

    + eval exec '"/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/java"' '"-Djava.util.logging.config.file=/Users/ryan/Library/Caches/IntelliJIdea12/tomcat/Unnamed_secure_post_3/conf/logging.properties"' -Xdebug -Xrunjdwp:transport=dt_socket,address=127.0.0.1:65523,suspend=y,server=n -Dcom.sun.management.jmxremote= -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=127.0.0.1 -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000 -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager '-Djava.endorsed.dirs="/usr/local/Cellar/tomcat/7.0.37/libexec/endorsed"' -classpath '"/usr/local/Cellar/tomcat/7.0.37/libexec/bin/bootstrap.jar:/usr/local/Cellar/tomcat/7.0.37/libexec/bin/tomcat-juli.jar"' '-Dcatalina.base="/Users/ryan/Library/Caches/IntelliJIdea12/tomcat/Unnamed_secure_post_3"' '-Dcatalina.home="/usr/local/Cellar/tomcat/7.0.37/libexec"' '-Djava.io.tmpdir="/usr/local/Cellar/tomcat/7.0.37/libexec/temp"' org.apache.catalina.startup.Bootstrap start
like image 343
Ryan Avatar asked Apr 04 '13 22:04

Ryan


People also ask

Why debug mode 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 *.

How do I debug Java code 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.

How do I enable Java debugging?

Click Java > JVM Settings tab. Under Debug Java Settings, select the Enable Debug checkbox. Provide JVM options as necessary by clicking the New button. If you substitute suspend=y, the JVM starts in suspended mode and stays suspended until a debugger attaches to it.


1 Answers

Problem was catalina.sh was calling setenv.sh which was setting JAVA_OPTS like this:

    JAVA_OPTS="$JAVA_OPTS -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000"

I don't know where this setenv.sh came from, as a co-worker's homebrew install of tomcat didn't have this file.

For now, I've configured IntelliJ debug to use catalina_idea_debug.sh, which is simply a copy of catalina.sh minus the call to setenv.sh. Works fine now.

like image 116
Ryan Avatar answered Oct 05 '22 23:10

Ryan