{"id":338,"date":"2026-10-13T16:41:00","date_gmt":"2026-10-13T16:41:00","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2013\/05\/17\/overview-of-emma\/"},"modified":"2026-10-13T16:41:00","modified_gmt":"2026-10-13T16:41:00","slug":"overview-of-emma","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/overview-of-emma\/","title":{"rendered":"EMMA for Java Code Coverage: Setup, Instrumentation Modes, and J2EE Workflow"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">EMMA is a tool for measuring coverage of Java software. It helps teams detect dead code and verify what parts of an application are actually exercised by test suites or interactive usage. This guide focuses on practical setup and deployment patterns from the original EMMA overview, especially for J2EE-style environments.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Originally published on 2013-05-17; fully revised and updated.<\/em><\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2013\/05\/emma-overview.png\" alt=\"EMMA overview\"\/><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\">What EMMA is designed to do<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The original EMMA design goals emphasized fast iterative development while still producing rich coverage information. In practical terms, teams used EMMA to keep coverage checks lightweight enough for frequent local and CI usage.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Measure code coverage for Java applications.<\/li><li>Highlight unexercised code paths and potential dead code.<\/li><li>Keep build-time and runtime overhead low enough for frequent feedback loops.<\/li><li>Support both small standalone applications and larger enterprise codebases.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Installation options for command-line usage<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The original article describes two primary ways to make EMMA available from the command line.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Method<\/th><th>How it works<\/th><th>When teams used it<\/th><th>Trade-off<\/th><\/tr><\/thead><tbody><tr><td>JRE extension<\/td><td>Copy <strong>emma.jar<\/strong> into the JRE <em>lib\/ext<\/em> directory used by your command-line Java runtime.<\/td><td>Convenient for repeated local use.<\/td><td>Introduces a third-party JAR as a global runtime extension.<\/td><\/tr><tr><td>Explicit classpath<\/td><td>Pass <strong>emma.jar<\/strong> in each EMMA Java invocation.<\/td><td>Safer when you do not want global JRE modification.<\/td><td>Slightly more verbose command lines.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php language-bash\"><span class=\"hljs-comment\"># Explicit classpath invocation pattern<\/span>\njava -cp \/path\/to\/emma.jar emma &#91;tool-arguments]\njava -cp \/path\/to\/emma.jar emmarun &#91;run-arguments]<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">On-the-fly vs offline instrumentation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The source distinguishes two usage modes. For many J2EE servers, offline instrumentation is the more reliable approach because of container-specific class loading behavior.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Mode<\/th><th>Best suited for<\/th><th>Instrumentation timing<\/th><th>Notes from the original guidance<\/th><\/tr><\/thead><tbody><tr><td>On-the-fly<\/td><td>Standalone applications<\/td><td>During runtime loading<\/td><td>Can be harder in some J2EE environments because class loading may bypass EMMA expectations.<\/td><\/tr><tr><td>Offline<\/td><td>J2EE framework-based applications<\/td><td>After compile, before packaging\/deployment<\/td><td>Recommended sequence is compile, instrument, package, deploy, run tests, collect coverage, generate report.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Offline instrumentation workflow for J2EE deployments<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For app servers such as WebLogic, WebSphere, Tomcat, or JBoss, the article recommends offline instrumentation to avoid class loader mismatches and missing reports.<\/p>\n\n\n\n<pre class=\"mermaid\">\nflowchart TD\n    A[Compile Java classes] --> B[Instrument classes or jars with EMMA instr]\n    B --> C[Package artifacts war ear jar]\n    C --> D[Deploy to application server]\n    D --> E[Run tests or interactive flows]\n    E --> F[Request coverage dump with ctl coverage.get]\n    F --> G[Generate coverage report]\n<\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Instrument target classes as a post-compilation step, or instrument JARs directly.<\/li><li>Package your application normally, but do <strong>not<\/strong> include <strong>emma.jar<\/strong> inside WAR\/EAR application libraries.<\/li><li>Place <strong>emma.jar<\/strong> in the container JRE extension path, or add it to the server classpath using server-specific configuration.<\/li><li>Deploy the instrumented artifacts and exercise the application through test cases or interactive usage.<\/li><li>Collect a coverage dump; the source recommends using the <strong>coverage.get<\/strong> control command via the <strong>ctl<\/strong> tool.<\/li><\/ul>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php language-bash\"><span class=\"hljs-comment\"># Example pattern for offline instrumentation<\/span>\njava -cp \/path\/to\/emma.jar emma instr -ip build\/classes -outmode fullcopy -d build\/instrumented\n\n<span class=\"hljs-comment\"># After deploying and running tests, request a coverage dump<\/span>\njava -cp \/path\/to\/emma.jar emma ctl &#91;connection-options] coverage.get<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">References and related integration pointers<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Original reference links from the source post:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/emma.sourceforge.net\/faq.html#q.runtime.appservers\">http:\/\/emma.sourceforge.net\/faq.html#q.runtime.appservers<\/a><\/li><li><a href=\"http:\/\/emma.sourceforge.net\/reference\/ch02s03.html#tool-ref.instr.outmodes\">http:\/\/emma.sourceforge.net\/reference\/ch02s03.html#tool-ref.instr.outmodes<\/a><\/li><li><a href=\"http:\/\/primates.ximian.com\/~flucifredi\/emma-HOWTO.html\">http:\/\/primates.ximian.com\/~flucifredi\/emma-HOWTO.html<\/a><\/li><li><a href=\"http:\/\/groovy.329449.n5.nabble.com\/EMMA-Code-Coverage-has-problem-with-Groovy-classes-td360560.html\">http:\/\/groovy.329449.n5.nabble.com\/EMMA-Code-Coverage-has-problem-with-Groovy-classes-td360560.html<\/a><\/li><\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The original post also mentions EMMA integration topics for Sonar, Hudson, and CruiseControl.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common pitfalls and best practices<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Prefer offline instrumentation for complex J2EE containers where class loading is not straightforward.<\/li><li>Keep instrumentation as an explicit build step so coverage behavior is reproducible.<\/li><li>Avoid bundling <strong>emma.jar<\/strong> inside application-level WAR\/EAR libs when following the server-level setup model described in the source.<\/li><li>Use a consistent coverage collection step (for example, <strong>coverage.get<\/strong>) in your test pipeline.<\/li><li>Validate old external documentation links and command arguments against your exact EMMA version before automating.<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>EMMA is a Java code coverage tool used to see which code paths are actually exercised by tests and runtime usage. This updated guide explains installation choices, instrumentation modes, and the offline J2EE workflow described in the original post.<\/p>\n","protected":false},"author":1,"featured_media":3763,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[62],"tags":[2337,1003,784,610,2334,1040,2331,514,2335,2336,341],"class_list":["post-338","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-code-analysis","tag-advantages-of-emma","tag-code","tag-code-analysis","tag-code-coverage","tag-code-coverage-tool","tag-coverage","tag-coverage-tools","tag-emma","tag-emma-overview","tag-overview-of-emma","tag-tool"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=338"}],"version-history":[{"count":3,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/338\/revisions"}],"predecessor-version":[{"id":79208,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/338\/revisions\/79208"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/3763"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=338"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=338"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}