blob: ca3960af0c510b903a5fa11114411c2fca6ef347 [file] [log] [blame]
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Debugging With IntelliJ</title><link rel="stylesheet" type="text/css" href="css/docbook.css"><meta name="generator" content="DocBook XSL Stylesheets V1.79.1"><meta name="keywords" content="jetty, servlet, servlet-api, cometd, http, websocket, eclipse, maven, java, server, software"><link rel="home" href="index.html" title="Jetty"><link rel="up" href="advanced-debugging.html" title="Chapter&nbsp;34.&nbsp;Debugging"><link rel="prev" href="enable-remote-debugging.html" title="Enable remote debugging"><link rel="next" href="debugging-with-eclipse.html" title="Debugging With Eclipse"><link xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" rel="shortcut icon" href="images/favicon.ico"><link rel="stylesheet" href="css/highlighter/foundation.css"><script src="js/highlight.pack.js"></script><script>
hljs.initHighlightingOnLoad();
</script><link type="text/css" rel="stylesheet" href="css/font-awesome/font-awesome.min.css"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><tr><td style="width: 25%"><a href="http://www.eclipse.org/jetty"><img src="images/jetty-header-logo.png" alt="Jetty Logo"></a><br><span style="font-size: small">
Version: 9.4.28-SNAPSHOT</span></td><td style="width: 50%"></td></tr></table><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Debugging With IntelliJ</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="enable-remote-debugging.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><th width="60%" align="center">Chapter&nbsp;34.&nbsp;Debugging<br><a accesskey="p" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></th><td width="20%" align="right">&nbsp;<a accesskey="n" href="debugging-with-eclipse.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr></table><hr></div><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="jetty-callout"><h5 class="callout"><a href="http://www.webtide.com/">Contact the core Jetty developers at
<span class="website">www.webtide.com</span></a></h5><p>
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ...
scalability guidance for your apps and Ajax/Comet projects ... development services for sponsored feature development
</p></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="debugging-with-intellij"></a>Debugging With IntelliJ</h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="section"><a href="debugging-with-intellij.html#_linking_with_intellij">Linking with IntelliJ</a></span></dt><dt><span class="section"><a href="debugging-with-intellij.html#intellij-within-intellij">Within IntelliJ</a></span></dt></dl></div><p>There are a number of options available to debug your application in IntelliJ.</p><p>If not done already prepare your application for remote debugging as described here: <a class="xref" href="enable-remote-debugging.html" title="Enable remote debugging">Enable remote debugging</a></p><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="_linking_with_intellij"></a>Linking with IntelliJ</h3></div></div></div><p>Next we need to link the IntelliJ project with the deployed webapp.</p><div class="orderedlist"><ol class="orderedlist" type="1"><li class="listitem"><p class="simpara">Within IntelliJ, open the project containing the webapp deployed into jetty that you want to debug. Select<span class="strong"><strong>Run &#8594; Edit Configurations</strong></span>.
Add a new configuration by clicking the "+" icon. Choose <span class="strong"><strong>Remote</strong></span>.
Make sure the port you choose is the same as the one you added in <a class="xref" href="enable-remote-debugging.html" title="Enable remote debugging">Enable remote debugging</a>.</p><p class="simpara"><span class="inlinemediaobject"><img src="images/intellij_new_remote_config.png" width="800" alt="image"></span></p></li><li class="listitem"><p class="simpara">Next in your webapp you can set a breakpoint within a servlet which when it is tripped will halt the remote jvm&#8217;s processing thread to await for debugging commands from your IntelliJ instance.
To set a breakpoint, simply open the servlet or any other class you want to debug and click left to the line you want to set the breakpoint at (where the red dot is on the next screenshot).
The red dot and red background on the line mark the breakpoint.</p><p class="simpara"><span class="inlinemediaobject"><img src="images/intellij_set_breakpoint.png" width="800" alt="image"></span></p></li><li class="listitem"><p class="simpara">Accessing that servlet within your browser, pointed at your remote debug configured jetty-distribution, should transition your IntelliJ instance to the standard debugger view.</p><p class="simpara"><span class="inlinemediaobject"><img src="images/intellij_debug_view.png" width="800" alt="image"></span></p></li></ol></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a name="intellij-within-intellij"></a>Within IntelliJ</h3></div></div></div><p>Since Jetty can be incredibly simple to embed, many people choose to create a small <code class="literal">main</code> method which they can launch directly within IntelliJ in order to more easily debug their entire application.
The best place to get started on this approach is to look through <a class="link" href="embedding-jetty.html" title="Embedding Jetty">] and the xref:embedded-examples[</a> sections.</p><p>Once you have a main method defined in order to launch your application, open the source file and right-click the main method.
Select <span class="strong"><strong>Debug</strong></span> or simply hit CTRL+SHIFT+D.
In your <span class="strong"><strong>Console</strong></span> tab within IntelliJ you should see your application startup and once it has completed startup you should be able to configure breakpoints and hit the Jetty instance as normal via your web browser.
The same thing works for unit tests.
Instead of the main method run debug on the test method you want to debug.</p><p><span class="inlinemediaobject"><img src="images/intellij_select_debug.png" width="800" alt="image"></span></p><p>Debugging in IntelliJ is extremely powerful.
For example it&#8217;s possible to have conditional breakpoints that only trigger a break if the configured conditions are met.
Have a look at the various tutorials in the internet or the <a class="link" href="http://www.jetbrains.com/idea/webhelp/getting-help.html" target="_top">IntelliJ documentation</a> for further details.</p><div class="blockquote"><blockquote class="blockquote"><div xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times" class="tip" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title"><i class="fa fa-lightbulb-o" aria-hidden="true"></i> Tip</h3><p>You can easily configure logging through a <code class="literal">jetty-logging.properties</code> file.
If this file is on your classpath then Jetty will use it for configuring logging, we use this approach extensively throughout Jetty development and it makes life ever so much easier.
You can see this in action in the <a class="xref" href="configuring-logging.html#configuring-jetty-stderrlog" title="The jetty-logging.properties file">The jetty-logging.properties file</a> section.</p></div></blockquote></div></div></div><script type="text/javascript">
SyntaxHighlighter.all()
</script><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="enable-remote-debugging.html"><i class="fa fa-chevron-left" aria-hidden="true"></i> Previous</a>&nbsp;</td><td width="20%" align="center"><a accesskey="u" href="advanced-debugging.html"><i class="fa fa-chevron-up" aria-hidden="true"></i> Top</a></td><td width="40%" align="right">&nbsp;<a accesskey="n" href="debugging-with-eclipse.html">Next <i class="fa fa-chevron-right" aria-hidden="true"></i></a></td></tr><tr><td width="40%" align="left" valign="top">Enable remote debugging&nbsp;</td><td width="20%" align="center"><a accesskey="h" href="index.html"><i class="fa fa-home" aria-hidden="true"></i> Home</a></td><td width="40%" align="right" valign="top">&nbsp;Debugging With Eclipse</td></tr></table></div><p xmlns:jfetch="java:org.eclipse.jetty.xslt.tools.JavaSourceFetchExtension" xmlns:fetch="java:org.eclipse.jetty.xslt.tools.SourceFetchExtension" xmlns:d="http://docbook.org/ns/docbook" xmlns:l="http://docbook.sourceforge.net/xmlns/l10n/1.0" xmlns:xslthl="http://xslthl.sf.net" xmlns:gcse="http://www.google.com" xmlns:date="http://exslt.org/dates-and-times"><div class="jetty-callout">
See an error or something missing?
<span class="callout"><a href="http://github.com/eclipse/jetty.project">Contribute to this documentation at
<span class="website"><i class="fa fa-github" aria-hidden="true"></i> Github!</span></a></span><span style="float: right"><i>(Generated: 2020-03-10)</i></span></div></p></body></html>