Installation
Manual installation
- Download the latest version from http://repository.ops4j.org/maven2/org/ops4j/pax/logging/.
- Deploy the downloaded bundle to your prefered OSGi framework
Using Pax Runner profile option
You can automatically include pax logging in your deployed installed bundles when using Pax Runner by using the profile option. Following is the most simple example to include a log profile:
pax-run "--profiles=log"
Using Pax Runner provisioning
You can automatically provision the pax logging bundles by using any of the scanners. Here are some examples:
- Using the dir scanner
- Download the pax logging bundles (see above) and place them in a folder
- Start a command line
cdto that folder- start pax runner:
pax-run
- Using the pom scanner
... <dependency> <groupId>org.ops4j.pax.logging</groupId> <artifactId>pax-logging-api</artifactId> <version>1.2.1</version> </dependency> <dependency> <groupId>org.ops4j.pax.logging</groupId> <artifactId>pax-logging-service</artifactId> <version>1.2.1</version> </dependency> ... - Using the file scanner
... mvn:org.ops4j.pax.logging/pax-logging-api/1.2.1 mvn:org.ops4j.pax.logging/pax-logging-service/1.2.1
Using Pax Construct
- Install Pax Construct http://www.ops4j.org/projects/pax/construct/
- Create a project using
pax-create-project(if you do not already have one) - Ensure that you have the following repository:
<repository> <id>ops4j.releases</id> <url>http://repository.ops4j.org/maven2/</url> </repository>
- Import pax logging api bundle using
pax-import-bundle -g org.ops4j.pax.logging -a pax-logging-api -v 1.2.1 - Import pax logging service bundle using
pax-import-bundle -g org.ops4j.pax.logging -a pax-logging-service -v 1.2.1 - Start
mvn pax:provision
A more detailed example is shown below:
# this assumes you are using Pax-Construct v1.1
# ---------------------------------------------
pax-create-project -g mygroup -a project
cd project
# add the OPS4J release repository, as Pax-Logging is not on central yet...
pax-add-repository -i ops4j.releases -u http://repository.ops4j.org/maven2/
pax-create-bundle -p mygroup.mybundle -n mybundle
# import the Pax-Logging bundles for the global project
pax-import-bundle -g org.ops4j.pax.logging -a pax-logging-api -v 1.2.1
pax-import-bundle -g org.ops4j.pax.logging -a pax-logging-service -v 1.2.1
# NOTE that by default this global set of imported bundles is NOT added to
# the classpath of individual bundles (this is to avoid potential clashes)
# but you can edit the pom.xml of individual bundles to add this classpath
# ... see example below ...
# BTW, the directory is 'mybundle' not 'mygroup.mybundle' because you chose
# a specific name using the -n option, and the directory comes from the name
cd mybundle
# here you have a choice if you want to compile against the Log4J API
# ==either==
# 1) import the Pax-Logging API bundle for this particular local bundle
pax-import-bundle -g org.ops4j.pax.logging -a pax-logging-api -v 1.2.1
# ==OR==
# 2) uncomment the following entry from the generated local bundle pom:
# <!--
# | uncomment to add all imported (non-local) bundles to your compilation classpath
# <dependency>
# <type>pom</type>
# <groupId>${parent.groupId}</groupId>
# <artifactId>provision</artifactId>
# <optional>true</optional>
# </dependency>
# -->
# to get the global classpath, including the logging bundles you just imported
# ==OR==
# 3) manually add the Log4J artifact to your bundle as a *compile* dependency
# <dependency>
# <groupId>log4j</groupId>
# <artifactId>log4j</artifactId>
# <version>1.2.13</version>
# <scope>compile</scope>
# <optional>true</optional>
# </dependency>
# do NOT add the Log4J artifact using pax-import-bundle, or add it using provided
# scope, as it will then be deployed onto the OSGi framework and potentially cause
# problems. Instead rely on the Pax-Logging API bundle at deploy time, even if you
# decide the compile against the real Log4J artifact at compile time.
# You can now add your Log4J call to the bundle activator and it should compile ok:
#
# org.apache.log4j.Logger.getLogger(this.getClass()).info("LOG4J message");
#
cd ..
# head back to the project root and let's try to build and deploy...
mvn clean install pax:provision
, multiple selections available,