Excerpt | ||
---|---|---|
| ||
Using the Apache Felix SCR Ant Task to generate Declarative Services and Metatype Service descriptors during an Ant driven Build. |
Note |
---|
Work is underway to create an Ant Task for the generation of Declarative Services and Metatype Service descriptors similar to what is supported for Maven. The goal is to support the same Java 5 Annotations and JavaDoc tags for Ant driven builds as are available for Maven builds. The description on this page is based on unreleased software which must be built from the Apache Felix trunk. A release will be available shortly. |
The SCR Ant Task is implemented in the org.apache.felix.scr.ant
library which must be registered as an Ant Task in the build file as follows:
Code Block | ||||
---|---|---|---|---|
| ||||
<project ...>
<taskdef
resource="scrtask.properties"
classpath="org.apache.felix.scr.ant-0.0.1-SNAPSHOT.jar" />
</project>
|
Of course the value you set in the classpath
attribute depends on the actual location of the org.apache.felix.scr.ant
JAR file.
Notes:
- The name of the task is
scr
- The task requires that the source files have already been compiled
Like the standard javac
Ant Task, the SCR Ant Task defines an implicit fileset which defines the source files to be scanned for Java 5 Annotations or JavaDoc Tags. In addition to the child elements available to Ant Fileset as defined for directory-based tasks the following task attributes:
Attribute | Required | Default | Description |
---|---|---|---|
scrdir | Yes | – | The root directory of the implicitly defined fileset denoting the files to consider for annotation and/or JavaDoc tag processing. |
destdir | Yes | – | The name of the directory where the descriptor files are generated into. This is also used as the directory where the compiled classes from the |
classpath | No | – | The class path used to load classes from to analyse for the descriptor file generation. Generally this will be the same class path as the one used to compile the sources. |
classpathRef | No | – | A reference to a class path used to load classes from to analyse for the descriptor file generation. Generally this will be the same class path as the one used to compile the sources. |
finalName | No |
|
...
| The name of the descriptor file to create. This file is always located inside the | ||
metaTypeName | No | | The name of the descriptor file to create. This file is always located inside the |
generateAccessors | No | | If this switch is turned on, the bind and unbind methods for unary references are automatically generated by the plugin. |
annotationTagProviders | |||
specVersion |
Example
The following is very simple example build file based on the Apache Sling JCR WebConsole bundle:
Code Block | ||||
---|---|---|---|---|
| ||||
<project default="scr" basedir=".">
<taskdef resource="scrtask.properties"
classpath="../org.apache.felix.scr.ant-0.0.1-SNAPSHOT.jar" />
<target name="init">
<property name="src" value="src/main/java" />
<property name="classes" value="target/classes" />
<property name="m2Repo" value="${user.home}/.m2/repository" />
<path id="dependencies">
<fileset dir="${m2Repo}">
<include name="javax/jcr/jcr/1.0/jcr-1.0.jar" />
<include name="org/apache/sling/org.apache.sling.jcr.api/2.0.6/org.apache.sling.jcr.api-2.0.6.jar" />
<include name="org/apache/felix/org.apache.felix.webconsole/3.0.0/org.apache.felix.webconsole-3.0.0.jar" />
<include name="javax/servlet/servlet-api/2.4/servlet-api-2.4.jar" />
<include name="org/apache/felix/org.apache.felix.scr.annotations/1.0.0/org.apache.felix.scr.annotations-1.0.0.jar" />
</fileset>
</path>
</target>
<target name="compile" depends="init">
<mkdir dir="${classes}" />
<javac srcdir="${src}" destdir="${classes}" classpathref="dependencies" />
</target>
<target name="scr" depends="compile">
<scr srcdir="${src}" destdir="${classes}" classpathref="dependencies" />
</target>
<target name="clean">
<delete dir="target" />
</target>
</project>
|