6

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
Community
  • 1
  • 1
Ryan
  • 106
  • 1
  • 8
  • Can you show the command line invocation that is actually being run (in catalina.sh when it invokes the 'java' executable)? – mpierce Apr 04 '13 at 22:22
  • I'm not following. I copy my war file to the tomcat webapps directory and run catalina. – Ryan Apr 04 '13 at 22:32
  • Add an `echo` statement in the Tomcat startup script when it starts java to see what are the actual options being used. – CrazyCoder Apr 05 '13 at 09:24
  • Here is what my debug config looks like in IntelliJ: http://cl.ly/image/3R1c12230Z1t I've modified the catalina.sh file to echo just before evaling the Java run command. However, I don't see this output in any logs. Not sure where to look. Tried catalina.out. Also nothing in the IntelliJ console. – Ryan Apr 05 '13 at 12:53
  • Updated original post with java run command. Clearly shows the duplicate jdwp configuration. I can't remove it from the IntelliJ options so I need to figure out where to remove it from the startup script. The catalina.sh file sets it but I've removed that already. JAVA_OPTS are being set somewhere else but I have yet to track that down. – Ryan Apr 05 '13 at 13:46
  • That is weird, look inside `catalina.sh`, these options are added only when you run it with `jpda start` command line arguments, while in the console it clearly shows that `run` is used. With `run` option Tomcat will use JVM options passed from IDEA via `JAVA_OPTS` and `JPDA_OPTS` will not be added. This works perfectly for me on Windows, Linux and Mac. – CrazyCoder Apr 05 '13 at 14:16
  • Noticed that you are running `deploy-local` Ant task via IDEA configuration. Could it be that your Ant task starts Tomcat in debug mode? – CrazyCoder Apr 05 '13 at 14:21
  • ant task definitely does not start tomcat. – Ryan Apr 05 '13 at 14:53
  • You need to figure out why `jpda` section in the `catalina.sh` file is getting executed without `jpda` parameter passed to the script. – CrazyCoder Apr 05 '13 at 15:08
  • The only place jdwp shows up in cataline.sh is in an if block. I had already commented out the entire block. – Ryan Apr 05 '13 at 15:15
  • Try to delete Tomcat server and run configuration in IDEA, then add them again. – CrazyCoder Apr 05 '13 at 15:26
  • i figured it out. catalina.sh was calling setenv.sh (same directory) and this was setting the java_opts. I don't know where this setenv.sh came from, as a co-worker's homebrew install doesn't have it. – Ryan Apr 05 '13 at 15:42

2 Answers2

3

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.

Ryan
  • 106
  • 1
  • 8
  • fyi, setenv.sh is the proposed way according to catalina.sh in order to include there properties. Nevertheless, as you pointed out, using the setenv.sh doesn't seem to work with Idea. – gpol Oct 03 '13 at 12:34
  • I also had this same issue in Intellij 15 with a tomcat run configuration on **Windows**. I just renamed the **setenv.bat** file to setenv.bat.old and then ran the configuration again and now debugging works. – Brod May 03 '16 at 16:02
0

Similar problem here with IntelliJ and JBoss. For me, there were JAVA_OPTS specified in standalone.conf containing jdwp configuration. Commenting this out lead me to be able to debug from IntelliJ.

Maybe this helps other searching for this phrase, because there's not much info around on the internet.