| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <html> |
| <!-- |
| |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. |
| The ASF licenses this file to You under the Apache License, Version 2.0 |
| (the "License"); you may not use this file except in compliance with |
| the License. You may obtain a copy of the License at |
| |
| https://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| <head> |
| <title>Apache Felix - Apache Felix SCR Plugin Frequently Asked Questions</title> |
| <link rel="icon" href="/res/favicon.ico"> |
| <link rel="stylesheet" href="/res/site.css" type="text/css" media="all"> |
| <link rel="stylesheet" href="/res/codehilite.css" type="text/css" media="all"> |
| <meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> |
| </head> |
| <body> |
| <div class="title"> |
| <div class="logo"> |
| <a href="https://felix.apache.org/"> |
| <img border="0" alt="Apache Felix" src="/res/logo.png"> |
| </a> |
| </div> |
| <div class="header"> |
| <a href="https://www.apache.org/"> |
| <img border="0" alt="Apache" src="/res/apache.png"> |
| </a> |
| </div> |
| </div> |
| |
| <div class="menu"> |
| <style type="text/css"> |
| /* The following code is added by mdx_elementid.py |
| It was originally lifted from http://subversion.apache.org/style/site.css */ |
| /* |
| * Hide class="elementid-permalink", except when an enclosing heading |
| * has the :hover property. |
| */ |
| .headerlink, .elementid-permalink { |
| visibility: hidden; |
| } |
| h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style> |
| <p><a href="/news.html">News</a> <br /> |
| <a href="/license.html">License</a> <br /> |
| <a href="/downloads.cgi">Downloads</a> <br /> |
| <a href="/documentation.html">Documentation</a> <br /> |
| <a href="/documentation/community/project-info.html">Project Info</a> <br /> |
| <a href="/documentation/community/contributing.html">Contributing</a> <br /> |
| <a href="/sitemap.html">Site Map</a> <br /> |
| <a href="https://www.apache.org/">ASF</a> <br /> |
| <a href="https://www.apache.org/security/">Security</a> <br /> |
| <a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a> <br /> |
| <a href="https://www.apache.org/foundation/thanks.html">Sponsors</a> </p> |
| <iframe |
| src="https://www.apache.org/ads/button.html" |
| style="border-width:0; float: left" |
| frameborder="0" |
| scrolling="no" |
| width="135" |
| height="135"> |
| </iframe> |
| </div> |
| |
| <div class="main"> |
| <div class="breadcrump" style="font-size: 80%;"> |
| <a href="/">Home</a> » <a href="/documentation.html">Documentation</a> » <a href="/documentation/faqs.html">Frequently Asked Questions</a> |
| </div> |
| |
| <h1>Apache Felix SCR Plugin Frequently Asked Questions</h1> |
| <style type="text/css"> |
| /* The following code is added by mdx_elementid.py |
| It was originally lifted from http://subversion.apache.org/style/site.css */ |
| /* |
| * Hide class="elementid-permalink", except when an enclosing heading |
| * has the :hover property. |
| */ |
| .headerlink, .elementid-permalink { |
| visibility: hidden; |
| } |
| h2:hover > .headerlink, h3:hover > .headerlink, h1:hover > .headerlink, h6:hover > .headerlink, h4:hover > .headerlink, h5:hover > .headerlink, dt:hover > .elementid-permalink { visibility: visible }</style> |
| <div class="toc"> |
| <ul> |
| <li><a href="#should-i-still-use-the-apache-felix-scr-annotations-over-the-official-osgi-annotations">Should I still use the Apache Felix SCR annotations over the official OSGi annotations?</a></li> |
| <li><a href="#why-are-the-standard-annotations-not-processed">Why are the (standard) annotations not processed?</a></li> |
| <li><a href="#syntax-error-when-enums-are-used">Syntax Error when Enums are used?</a></li> |
| <li><a href="#noclassdeffounderror-during-build">NoClassDefFoundError during build</a></li> |
| <li><a href="#no-components-or-services-available-at-runtime">No components or services available at runtime</a></li> |
| </ul> |
| </div> |
| <p>This page provides answers to frequently asked questions using the Maven |
| SCR Plugin. See <a href="/documentation/subprojects/apache-felix-maven-scr-plugin.html">Apache Felix Maven SCR Plugin</a> |
| for documentation on that plugin.</p> |
| <h2 id="should-i-still-use-the-apache-felix-scr-annotations-over-the-official-osgi-annotations">Should I still use the Apache Felix SCR annotations over the official OSGi annotations?<a class="headerlink" href="#should-i-still-use-the-apache-felix-scr-annotations-over-the-official-osgi-annotations" title="Permanent link">¶</a></h2> |
| <p>Starting with the R6 release of the OSGi Declarative Services and Metatype specification, the official annotations support the same features as the Apache Felix SCR annotations in a more elegant manner and even provide additional functionality. Therefore the Apache Felix SCR annotations are now in maintenance mode and therefore you should rather use the official annotations. The Apache Felix maven-bundle-plugin, version 3.0.1 or higher supports those directly and there is no need for an additional plugin anymore.</p> |
| <h2 id="why-are-the-standard-annotations-not-processed">Why are the (standard) annotations not processed?<a class="headerlink" href="#why-are-the-standard-annotations-not-processed" title="Permanent link">¶</a></h2> |
| <p>In order to process any annotations, a processor for them needs to be added as a dependency to your project. There are currently two different processors, one for the annotations defined within the Apache Felix project and another one for the standard annotations from the Declarative Services specification.</p> |
| <h2 id="syntax-error-when-enums-are-used">Syntax Error when Enums are used?<a class="headerlink" href="#syntax-error-when-enums-are-used" title="Permanent link">¶</a></h2> |
| <p>During a SCR plugin run, a syntax error might occur if enums are used in the source code. This is a know problem of the used QDox version that reads the Java source files. Usually this happens when an enum is used inline and does not end with a ";". So adding this character should solve the problem:</p> |
| <div class="codehilite"><pre><span class="kd">public</span> <span class="kd">interface</span> <span class="nc">MyTest</span> <span class="o">{</span> |
| |
| <span class="cm">/** more error codes may be added */</span> |
| <span class="kd">enum</span> <span class="n">Result</span> <span class="o">{</span> |
| <span class="n">OK</span><span class="o">,</span> <span class="n">UNKNOWN</span><span class="o">,</span> <span class="n">ERROR</span><span class="o">,</span> <span class="n">DENIED</span> |
| <span class="o">};</span> <span class="c1">// <!-- HERE</span> |
| |
| <span class="cm">/** @return the result */</span> |
| <span class="kd">public</span> <span class="kt">void</span> <span class="nf">getResult</span><span class="o">();</span> |
| <span class="o">}</span> |
| </pre></div> |
| |
| |
| <h2 id="noclassdeffounderror-during-build">NoClassDefFoundError during build<a class="headerlink" href="#noclassdeffounderror-during-build" title="Permanent link">¶</a></h2> |
| <p>This error might happen with older versions of the Maven SCR Plugins in combination with javadoc tags or newer versions in combination with the annotations. |
| In both cases, the scanned classes have to be loaded and static fields have to be initialized. If you have have for example something like</p> |
| <div class="codehilite"><pre><span class="kd">private</span> <span class="kd">static</span> <span class="kd">final</span> <span class="n">org</span><span class="o">.</span><span class="na">slf4f</span><span class="o">.</span><span class="na">Logger</span> <span class="n">LOGGER</span> <span class="o">=</span> <span class="n">org</span><span class="o">.</span><span class="na">slf4j</span><span class="o">.</span><span class="na">LoggerFactory</span><span class="o">.</span><span class="na">getLogger</span><span class="o">(</span><span class="s">"name"</span><span class="o">);</span> |
| </pre></div> |
| |
| |
| <p>in your code, during the plugin run, a slf4j logger is tried to be instantiated. This requires an implementation of the logger. Ususally your module only depends on the slf4j API and therefore a </p> |
| <div class="codehilite"><pre><span class="n">java</span><span class="p">.</span><span class="n">lang</span><span class="p">.</span><span class="n">NoClassDefFoundError</span><span class="p">:</span> <span class="n">org</span><span class="o">/</span><span class="n">slf4j</span><span class="o">/</span><span class="n">impl</span><span class="o">/</span><span class="n">StaticLoggerBinder</span> |
| </pre></div> |
| |
| |
| <p>is thrown - this often happens with slf4j but might also happen with other libraries.</p> |
| <p>In these cases you should add a dependency to the missing class to the dependency list of the plugin, for example:</p> |
| <div class="codehilite"><pre><span class="nt"><plugin></span> |
| <span class="nt"><groupId></span>org.apache.felix<span class="nt"></groupId></span> |
| <span class="nt"><artifactId></span>maven-scr-plugin<span class="nt"></artifactId></span> |
| <span class="nt"><version></span>...<span class="nt"></version></span> |
| <span class="nt"><dependencies></span> |
| <span class="nt"><dependency></span> |
| <span class="nt"><groupId></span>org.slf4j<span class="nt"></groupId></span> |
| <span class="nt"><artifactId></span>slf4j-simple<span class="nt"></artifactId></span> |
| <span class="nt"><version></span>1.5.2<span class="nt"></version></span> |
| <span class="nt"></dependency></span> |
| <span class="nt"></dependencies></span> |
| ... |
| <span class="nt"></plugin></span> |
| </pre></div> |
| |
| |
| <p>or in the special case of slf4j, using slf4j API 1.6 or higher solves the problem as well</p> |
| <h2 id="no-components-or-services-available-at-runtime">No components or services available at runtime<a class="headerlink" href="#no-components-or-services-available-at-runtime" title="Permanent link">¶</a></h2> |
| <p>The SCR plugin generates a descriptor for Declarative Services (see OSGi compendium specification). Therefore at runtime, you must have an implementation of DS running in your OSGi framework, like the SCR implementation from the Apache Felix project.</p> |
| <p>Otherwise your bundle might resolve fine, however no services are registered with the service registry and no components are activated.</p> |
| <div class="timestamp" style="margin-top: 30px; font-size: 80%; text-align: right;"> |
| Rev. 1742680 by cziegeler on Sat, 7 May 2016 00:34:10 +0000 |
| </div> |
| <div class="trademarkFooter"> |
| Apache Felix, Felix, Apache, the Apache feather logo, and the Apache Felix project |
| logo are trademarks of The Apache Software Foundation. All other marks mentioned |
| may be trademarks or registered trademarks of their respective owners. |
| </div> |
| </div> |
| </body> |
| </html> |