Apache Felix SCR Plugin Frequently Asked Questions

Syntax Error when Enums are used?

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:

public interface MyTest {

     /** more error codes may be added */
     enum Result {
 	OK, UNKNOWN, ERROR, DENIED
     };     // <!-- HERE
 
     /** @return the result */
     public void getResult(); 
  }

NoClassDefFoundError during build

If the javadoc tags are used (and not the annotations) then the QDox library is used to parse/introspect the java class. For this the classes have to be loaded and static fields have to be initialized. If you have have for example something like

  private static final org.slf4f.Logger LOGGER = org.slf4j.LoggerFactory.getLogger("name");

in your code, during the plugin run, a slf4j logger is tried to instantiated. This requires an implementation of the logger. Ususally your module only depends on the slf4j API and therefore a

java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

is thrown - this often happens with slf4j but might also happen with other libraries.

In these cases you should add a dependency to the missing class to the dependency list of the plugin, like:

     <plugin>
         <groupId>org.apache.felix</groupId>
         <artifactId>maven-scr-plugin</artifactId>
         <version>1.4.2</version>
         <dependencies>
             <dependency>
                 <groupId>org.slf4j</groupId>
                 <artifactId>slf4j-simple</artifactId>
                 <version>1.5.2</version>
             </dependency>
         </dependencies>
  • No labels