How to enable remote debugging from IntelliJ with Tomcat?
问题:
回答1:
Use Tomcat Run/Debug Configuration. Click the button and choose new Remote
configuration. In the Configuration
tab copy the JVM options suggested by IDEA.
Run Tomcat with the suggested JVM options:
set JAVA_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,address=1317,suspend=n,server=y
startup
Press Debug button in IDEA.
Otherwise it's the same as for Local Tomcat, check the tutorial.
Note that deploying to Tomcat is available only in IDEA Ultimate, but you can still manually deploy to Tomcat on your own and use Java's remote debug features using the free edition.
回答2:
Assume you start Tomcat standalone and attach debugger remotely to it from IntelliJ IDE.
1) Start Tomcat in debug mode
$TOMCAT_HOME/bin/catalina.sh jpda start
By default JPDA_ADDRESS is defined as "localhost:8000" in catalina.sh
Change to a different port as need
2) In IntelliJ IDE
Click Run > Edit Configurations
Click + icon on the top-left toolbar
Click Remote
Enter a name you want in Name input box
Enter 8000 in Port input box under Settings section
3) Click Apply, then OK
4) Run > Debug..., Click the configuration you just created
Note:
1) This should work with other remote JPDA instances such as WebLogic, JBoss, etc.
2) Documentation environment: Linux, IntelliJ IDEA 15.0.2
回答3:
just start catalina using following command:
catalina jpda start
By default tomcat will start and listen on port 8000.
See also http://wiki.apache.org/tomcat/FAQ/Developing#Q1
回答4:
Remote debugging of web applications running in Tomcat 7 is extremly convenient in IntelliJ IDEA 12 if you use Maven!
Just configure your pom-file to use the tomcat7-maven-plugin, eg:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
</plugin>
Then use the "Maven Projects" tool window to start the tomcat7:run goal in debug mode (see screenshot).
回答5:
In Intellij Idea:
Click on Run -> Edit Configurations -> Add New Configurations ("+" icon)
Click on Remote
Set Host and Port
Copy content of Command line arguments for running remote JVM, for example:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000
If you use Tomcat Service (for Tomcat 9):
Go to %TOMCAT_INSTALL_DIR%/bin
Run tomcat9w.exe
Click on Java tab
In Java Options Paste the copied text:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000
Apply.
回答6:
you can set
export CATALINA_OPTS="$CATALINA_OPTS -agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n"
in setenv.sh
file in bin
tomcat directory (remote server) and restart it.
then just you should add Remote
in Run/Debug Configurations in intellij and set Host
to remote server and Port
8000
回答7:
Add these two line to your bin/setenv.sh
export JPDA_ADDRESS="5005"
export JPDA_TRANSPORT="dt_socket"
Add remote Run/Debug Configuration in IntelliJ IDEA. (see the answer from @Jonathan L). You can keep the default port '5005'.
Start tomcat,
catalina.sh jpda run
Then simply run debug on the IDE.