blob: 69da59debfa637b2ab65c04e730186f28f6d14b0 [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Apache TomEE</title>
<meta name="description"
content="Apache TomEE is a lightweight, yet powerful, JavaEE Application server with feature rich tooling." />
<meta name="keywords" content="tomee,asf,apache,javaee,jee,shade,embedded,test,junit,applicationcomposer,maven,arquillian" />
<meta name="author" content="Luka Cvetinovic for Codrops" />
<link rel="icon" href="../../../../favicon.ico">
<link rel="icon" type="image/png" href="../../../../favicon.png">
<meta name="msapplication-TileColor" content="#80287a">
<meta name="theme-color" content="#80287a">
<link rel="stylesheet" type="text/css" href="../../../../css/normalize.css">
<link rel="stylesheet" type="text/css" href="../../../../css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="../../../../css/owl.css">
<link rel="stylesheet" type="text/css" href="../../../../css/animate.css">
<link rel="stylesheet" type="text/css" href="../../../../fonts/font-awesome-4.1.0/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="../../../../fonts/eleganticons/et-icons.css">
<link rel="stylesheet" type="text/css" href="../../../../css/jqtree.css">
<link rel="stylesheet" type="text/css" href="../../../../css/idea.css">
<link rel="stylesheet" type="text/css" href="../../../../css/cardio.css">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-2717626-1']);
_gaq.push(['_setDomainName', 'apache.org']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</head>
<body>
<div class="preloader">
<img src="../../../../img/loader.gif" alt="Preloader image">
</div>
<nav class="navbar">
<div class="container">
<div class="row"> <div class="col-md-12">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/">
<span>
<img src="../../../../img/logo-active.png">
</span>
Apache TomEE
</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right main-nav">
<li><a href="../../../../docs.html">Documentation</a></li>
<li><a href="../../../../community/index.html">Community</a></li>
<li><a href="../../../../security/security.html">Security</a></li>
<li><a href="../../../../download-ng.html">Downloads</a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div></div>
</div>
<!-- /.container-fluid -->
</nav>
<div id="main-block" class="container main-block">
<div class="row title">
<div class="col-md-12">
<div class='page-header'>
<h1>Debugging an Apache</h1>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div id="preamble">
<div class="sectionbody">
<div class="paragraph">
<p>Stepping through the <a href="http://tomee.apache.org/apache-tomee.html">TomEE</a>
source code is a must-to-follow step if you want to understand how TomEE
works and later contribute. This is a guide to quickly start your
debugging session with TomEE as a TomEE developer.</p>
</div>
<div class="paragraph">
<p>This guide assumes that:</p>
</div>
<div class="ulist">
<ul>
<li>
<p>Linux is the OS</p>
</li>
<li>
<p>IntelliJ IDEA 13.1.3 is the IDE</p>
</li>
<li>
<p>Maven 3.0.5 or better is installed</p>
</li>
</ul>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_download_the_source_code">Download the Source Code</h2>
<div class="sectionbody">
<div class="paragraph">
<p>For beginners it is recommended not to start with the trunk, because it
is common to have some blockers or non-stable functionality which could
bring your learning to a halt. So first start with the latest stable
released source code. Move to trunk once you are ready to do some code
modification on TomEE.</p>
</div>
<div class="paragraph">
<p><a href="http://www.apache.org/dyn/closer.cgi/tomee/tomee-1.7.1/openejb-4.7.1-source-release.zip">Click
here to download TomEE 1.7.1 Source code</a></p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_build_the_source_code">Build the Source Code</h2>
<div class="sectionbody">
<div class="paragraph">
<p>First extract the zip file named <strong>openejb-4.7.1-source-release.zip</strong> to
any location. Lets assume it is your home folder.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
<p>unzip openejb-4.7.1-source-release -d ~</p>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>The above command will create the <strong>openejb-4.7.1</strong> directory in your home
directory.</p>
</div>
<div class="paragraph">
<p>Even though you can do a full build, We will run the following command
to do a quick build so that you can have your meal before your hunger
kills you.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
<p>mvn -Pquick -Dsurefire.useFile=false -DdisableXmlReport=true
-DuniqueVersion=false -ff -Dassemble -DskipTests -DfailIfNoTests=false
clean install</p>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>More details about building the product from the source can be found
<a href="http://tomee.apache.org/dev/source-code.html">here</a>.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_deploy_tomee">Deploy TomEE</h2>
<div class="sectionbody">
<div class="paragraph">
<p>The TomEE build builds several distributions (zip &amp; war files) to cater
the different needs of different users. Here we discuss about the tomee
plus distribution &amp; TomEE war distribution only. TomEE+ is the full
feature packed distribution from TomEE.</p>
</div>
<div class="paragraph">
<p>TomEE+ zip location:</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
<p>~/openejb-4.7.1/tomee/apache-tomee/target/apache-tomee-plus-1.7.1.zip</p>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>Unzip the zip into your home directory (or any other location)</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
<p>unzip
~/openejb-4.7.1/tomee/apache-tomee/target/apache-tomee-plus-1.7.1.zip -d
~</p>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>You will find the directory <strong>apache-tomee-plus-1.7.1</strong> in your home
folder. Lets run the TomEE.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
<p>cd ~/apache-tomee-plus-1.7.1/bin ./catalina.sh run</p>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>"INFO: Server startup in xxxx ms" is the Green light!</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_prepare_your_ide">Prepare your IDE</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Lets prepare our IntelliJ IDEA for the debugging session.</p>
</div>
<div class="paragraph">
<p>Start IntelliJ IDEA and Click the Import Project link</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="idea1.png" alt="image"></span></p>
</div>
<div class="paragraph">
<p>Select the ~/openejb-4.7.1 directory and press OK</p>
</div>
<div class="paragraph">
<p>Select import project from external model &amp; Maven as the external model.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="idea3.png" alt="image"></span></p>
</div>
<div class="paragraph">
<p>Press Next on this screen.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="idea4.png" alt="image"></span></p>
</div>
<div class="paragraph">
<p>Select the main profile.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="idea6.png" alt="image"></span></p>
</div>
<div class="paragraph">
<p>Select the org.apache.openejb:openejb:4.7.1</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="idea7.png" alt="image"></span></p>
</div>
<div class="paragraph">
<p>Select the JDK you want to use with.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="idea8.png" alt="image"></span></p>
</div>
<div class="paragraph">
<p>Give the project a name and press Finish.</p>
</div>
<div class="paragraph">
<p><span class="image"><img src="idea9.png" alt="image"></span></p>
</div>
<div class="paragraph">
<p>Now your IDE will load the project.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_first_breakpoint">First Breakpoint</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Next step is to put a breakpoint at the place where the code is
triggered. Lets understand how the code is triggered.</p>
</div>
<div class="paragraph">
<p>TomEE+ is created on top of Tomcat. TomEE registers a Tomcat Lifecycle
Listener <strong>"org.apache.tomee.catalina.ServerListener"</strong> on <strong>server.xml</strong>
file.</p>
</div>
<div class="paragraph">
<p>All the Tomcat lifecycle events i.e. before_init, after_init, start,
before_stop etc&#8230;&#8203; are received by the <strong>lifecycleEvent</strong> method of the
ServerListener.</p>
</div>
<div class="paragraph">
<p>The execution of TomEE code starts in this lifecycleEvent method. So the
first breakpoint should be on the lifecycleEvent method.</p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_run_tomee_in_debug_mode">Run TomEE+ in debug mode</h2>
<div class="sectionbody">
<div class="paragraph">
<p>If you simply run <strong>catalina.sh jpda run</strong> in the bin folder of tomee
deployment, the server starts in the debug mode but it will quckly pass
your breakpoint before you attach your IDE to the server process.</p>
</div>
<div class="paragraph">
<p>So we set<strong> JPDA_SUSPEND="y"</strong> before we start our debugging. This will
tell the server "Do not proceed until the Debugger tool is attached to
the process"</p>
</div>
<div class="paragraph">
<p>The convenient way of doing this is adding this line to catalina.sh file
right after the #!/bin/sh line.</p>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
<p>= !/bin/sh JPDA_SUSPEND="y"</p>
</div>
<div class="paragraph">
<p>Now to time to run TomEE+ on debug mode.</p>
</div>
</blockquote>
</div>
<div class="quoteblock">
<blockquote>
<div class="paragraph">
<p>~/apache-tomee-plus-1.7.1/bin/catalina.sh jpda run</p>
</div>
</blockquote>
</div>
<div class="paragraph">
<p>The terminal should hang with the message <strong>"Listening for transport
dt_socket at address: 8000"</strong></p>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_attach_intellij_idea_debugger">Attach IntelliJ IDEA debugger</h2>
<div class="sectionbody">
<div class="ulist">
<ul>
<li>
<p>Menu Bar &gt; Run &gt; Edit Configurations</p>
</li>
<li>
<p>Press the "<strong>+</strong>" button on the top left corner to get the Add new
configuration menu</p>
</li>
<li>
<p>Select "Remote" from the Add new configuration menu</p>
</li>
<li>
<p>Give a name (I gave "TomEE DEBUG") to this new configuration and set
the Port to 8000</p>
</li>
<li>
<p>Click OK.</p>
</li>
</ul>
</div>
<div class="paragraph">
<p><span class="image"><img src="idea10.png" alt="image"></span></p>
</div>
<div class="paragraph">
<p>To start debugging your TomEE+</p>
</div>
<div class="paragraph">
<p>Main Menu &gt; Run &gt; Debug TomEE DEBUG</p>
</div>
<div class="paragraph">
<p>Congratulations! You hit the break point you put at the startup of the
TomEE code. Carry on with your debugging session to learn more.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<footer>
<div class="container">
<div class="row">
<div class="col-sm-6 text-center-mobile">
<h3 class="white">Be simple. Be certified. Be Tomcat.</h3>
<h5 class="light regular light-white">"A good application in a good server"</h5>
<ul class="social-footer">
<li><a href="https://www.facebook.com/ApacheTomEE/"><i class="fa fa-facebook"></i></a></li>
<li><a href="https://twitter.com/apachetomee"><i class="fa fa-twitter"></i></a></li>
<li><a href="https://plus.google.com/communities/105208241852045684449"><i class="fa fa-google-plus"></i></a></li>
</ul>
</div>
<div class="col-sm-6 text-center-mobile">
<div class="row opening-hours">
<div class="col-sm-3 text-center-mobile">
<h5><a href="../../../../latest/docs/" class="white">Documentation</a></h5>
<ul class="list-unstyled">
<li><a href="../../../../latest/docs/admin/configuration/index.html" class="regular light-white">How to configure</a></li>
<li><a href="../../../../latest/docs/admin/file-layout.html" class="regular light-white">Dir. Structure</a></li>
<li><a href="../../../../latest/docs/developer/testing/index.html" class="regular light-white">Testing</a></li>
<li><a href="../../../../latest/docs/admin/cluster/index.html" class="regular light-white">Clustering</a></li>
</ul>
</div>
<div class="col-sm-3 text-center-mobile">
<h5><a href="../../../../latest/examples/" class="white">Examples</a></h5>
<ul class="list-unstyled">
<li><a href="../../../../latest/examples/simple-cdi-interceptor.html" class="regular light-white">CDI Interceptor</a></li>
<li><a href="../../../../latest/examples/rest-cdi.html" class="regular light-white">REST with CDI</a></li>
<li><a href="../../../../latest/examples/ejb-examples.html" class="regular light-white">EJB</a></li>
<li><a href="../../../../latest/examples/jsf-managedBean-and-ejb.html" class="regular light-white">JSF</a></li>
</ul>
</div>
<div class="col-sm-3 text-center-mobile">
<h5><a href="../../../../community/index.html" class="white">Community</a></h5>
<ul class="list-unstyled">
<li><a href="../../../../community/contributors.html" class="regular light-white">Contributors</a></li>
<li><a href="../../../../community/social.html" class="regular light-white">Social</a></li>
<li><a href="../../../../community/sources.html" class="regular light-white">Sources</a></li>
</ul>
</div>
<div class="col-sm-3 text-center-mobile">
<h5><a href="../../../../security/index.html" class="white">Security</a></h5>
<ul class="list-unstyled">
<li><a href="http://apache.org/security" target="_blank" class="regular light-white">Apache Security</a></li>
<li><a href="http://apache.org/security/projects.html" target="_blank" class="regular light-white">Security Projects</a></li>
<li><a href="http://cve.mitre.org" target="_blank" class="regular light-white">CVE</a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="row bottom-footer text-center-mobile">
<div class="col-sm-12 light-white">
<p>Copyright &copy; 1999-2016 The Apache Software Foundation, Licensed under the Apache License, Version 2.0. Apache TomEE, TomEE, Apache, the Apache feather logo, and the Apache TomEE project logo are trademarks of The Apache Software Foundation. All other marks mentioned may be trademarks or registered trademarks of their respective owners.</p>
</div>
</div>
</div>
</footer>
<!-- Holder for mobile navigation -->
<div class="mobile-nav">
<ul>
<li><a hef="../../../../latest/docs/admin/index.html">Administrators</a>
<li><a hef="../../../../latest/docs/developer/index.html">Developers</a>
<li><a hef="../../../../latest/docs/advanced/index.html">Advanced</a>
<li><a hef="../../../../community/index.html">Community</a>
</ul>
<a href="#" class="close-link"><i class="arrow_up"></i></a>
</div>
<!-- Scripts -->
<script src="../../../../js/jquery-1.11.1.min.js"></script>
<script src="../../../../js/owl.carousel.min.js"></script>
<script src="../../../../js/bootstrap.min.js"></script>
<script src="../../../../js/wow.min.js"></script>
<script src="../../../../js/typewriter.js"></script>
<script src="../../../../js/jquery.onepagenav.js"></script>
<script src="../../../../js/tree.jquery.js"></script>
<script src="../../../../js/highlight.pack.js"></script>
<script src="../../../../js/main.js"></script>
</body>
</html>