====== Karaf Tutorial ======
* Starting: http://stackoverflow.com/questions/23164857/osgi-beginners-tutorials-are-outdated-is-there-a-new-standard
* From an answer:
* http://blog.knowhowlab.org/2010/06/osgi-tutorial-from-project-structure-to.html
* http://blog.knowhowlab.org/2010/10/osgi-tutorial-4-ways-to-activate-code.html
* Examples:
* https://github.com/ops4j/org.ops4j.pax.web/tree/web-6.0.1/samples
* https://github.com/cschneider/Karaf-Tutorial/blob/master/cxf/personservice-rest/pom.xml
* These look good too:
* shows both bundle activation and blueprint: http://www.hascode.com/2012/04/wiring-made-easy-using-osgi-blueprint-and-apache-karaf/
* http://blog.nanthrax.net/2011/12/overview-on-apache-karaf-pax-web-and-camel-archetypes/
* http://www.hascode.com/2012/04/wiring-made-easy-using-osgi-blueprint-and-apache-karaf/
* ETCs: http://enroute.osgi.org/
Others:
* https://karaf.apache.org/projects.html
* http://yveszoundi.blogspot.de/2012/10/a-quick-look-at-apache-karaf.html
* http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial.html
====== - Start from scratch ======
====== - Parent Pom ======
* http://docs.opendaylight.org/en/stable-boron/developer-guide/odl-parent-developer-guide.html
===== - What karaf provides? =====
==== - Karaf feature ====
* standard: https://github.com/apache/karaf/blob/karaf-4.1.x/assemblies/features/standard/src/main/feature/feature.xml
* enterprise: https://github.com/apache/karaf/blob/karaf-4.1.x/assemblies/features/enterprise/src/main/feature/feature.xml
* Auto generate feature.xml from maven deps: https://svn.apache.org/repos/asf/karaf/site/production/manual/latest-3.0.x/karaf-maven-plugin.html
* Set dependency as runtime in mvn so available bundles provided by karaf not get generated.
* http://karaf.922171.n3.nabble.com/What-version-of-slf4j-is-provided-in-karaf-td4041602.html
* https://github.com/wav/osgi-tooling/issues/9
==== - Adding feature ====
* https://karaf.apache.org/manual/latest/#_feature_bundles
feature:repo-add command.
The feature:repo-add command requires the name/url argument. This argument accepts:
* a feature repository URL. It’s an URL directly to the features XML file. Any URL described in the [Artifacts repositories and URLs section|urls] of the user guide is supported.
* a feature repository name defined in the etc/org.apache.karaf.features.repos.cfg configuration file.
The etc/org.apache.karaf.features.repos.cfg defines a list of "pre-installed/available" features repositories:
#
# This file describes the features repository URL
# It could be directly installed using feature:repo-add command
#
enterprise=mvn:org.apache.karaf.features/enterprise/LATEST/xml/features
spring=mvn:org.apache.karaf.features/spring/LATEST/xml/features
cellar=mvn:org.apache.karaf.cellar/apache-karaf-cellar/LATEST/xml/features
cave=mvn:org.apache.karaf.cave/apache-karaf-cave/LATEST/xml/features
camel=mvn:org.apache.camel.karaf/apache-camel/LATEST/xml/features
camel-extras=mvn:org.apache-extras.camel-extra.karaf/camel-extra/LATEST/xml/features
cxf=mvn:org.apache.cxf.karaf/apache-cxf/LATEST/xml/features
cxf-dosgi=mvn:org.apache.cxf.dosgi/cxf-dosgi/LATEST/xml/features
cxf-xkms=mvn:org.apache.cxf.services.xkms/cxf-services-xkms-features/LATEST/xml
activemq=mvn:org.apache.activemq/activemq-karaf/LATEST/xml/features
jclouds=mvn:org.apache.jclouds.karaf/jclouds-karaf/LATEST/xml/features
openejb=mvn:org.apache.openejb/openejb-feature/LATEST/xml/features
wicket=mvn:org.ops4j.pax.wicket/features/LATEST/xml/features
hawtio=mvn:io.hawt/hawtio-karaf/LATEST/xml/features
pax-cdi=mvn:org.ops4j.pax.cdi/pax-cdi-features/LATEST/xml/features
pax-jdbc=mvn:org.ops4j.pax.jdbc/pax-jdbc-features/LATEST/xml/features
pax-jpa=mvn:org.ops4j.pax.jpa/pax-jpa-features/LATEST/xml/features
pax-web=mvn:org.ops4j.pax.web/pax-web-features/LATEST/xml/features
pax-wicket=mvn:org.ops4j.pax.wicket/pax-wicket-features/LATEST/xml/features
ecf=http://download.eclipse.org/rt/ecf/latest/site.p2/karaf-features.xml
decanter=mvn:org.apache.karaf.decanter/apache-karaf-decanter/LATEST/xml/features
You can directly provide a features repository name to the feature:repo-add command. For install, to install Apache Karaf Cellar, you can do:
karaf@root()> feature:repo-add cellar
Adding feature url mvn:org.apache.karaf.cellar/apache-karaf-cellar/LATEST/xml/features
When you don’t provide the optional version argument, Apache Karaf installs the latest version of the features repository available. You can specify a target version with the version argument:
karaf@root()> feature:repo-add cellar 4.0.0.RC1
Adding feature url mvn:org.apache.karaf.cellar/apache-karaf-cellar/4.0.0.RC1/xml/features
Instead of providing a features repository name defined in the etc/org.apache.karaf.features.repos.cfg configuration file, you can directly provide the features repository URL to the feature:repo-add command:
karaf@root()> feature:repo-add mvn:org.apache.karaf.cellar/apache-karaf-cellar/4.0.0.RC1/xml/features
Adding feature url mvn:org.apache.karaf.cellar/apache-karaf-cellar/4.0.0.RC1/xml/features
By default, the feature:repo-add command just registers the features repository, it doesn’t install any feature. If you specify the -i option, the feature:repo-add command registers the features repository and installs all features described in this features repository:
karaf@root()> feature:repo-add -i cellar
==== - tbd ====
===== - Deploy with feature =====
* https://karaf.apache.org/manual/latest/#_deployer
You can "hot deploy" a features XML by dropping the file directly in the deploy folder.
Apache Karaf provides a features deployer.
When you drop a features XML in the deploy folder, the features deployer does: * register the features XML as a features repository * the features with install attribute set to "auto" will be automatically installed by the features deployer.
For instance, dropping the following XML in the deploy folder will automatically install feature1 and feature2, whereas feature3 won’t be installed:
...
...
...
====== - Troubleshooting bundle ======
feature:install -v feature_name
bundle:list
la
feature:list | grep
feature:info
service:list
service:list NamespaceHandler
service:list Datasource
bundle:tree-show [bundle-id]
exports | grep -i javax.transaction
karaf@root()> bundle:watch *
will monitor all bundles that have a location matching mvn:* and -SNAPSHOT in their URL.
For not snapshot bundles use bundle:update
bundle:update sd-rest more-bundle-name [ids, name/version]
Bundle:refresh should update all depending bundles:
bundle:refresh sd-rest more-bundle-name [ids, name/version]
list -t 0 -s | grep aries.transaction.manager
===== - javax.transaction =====
karaf@root()> bundle:list | grep -i directory 17:24:34
163 │ GracePeriod │ 80 │ 1.0.0.SNAPSHOT │ directory service impl
164 │ Active │ 80 │ 1.0 │ directory-api Bundle
karaf@root()> bundle:tree-show 163 17:27:00
Bundle directory [163] is currently ACTIVE
directory [163]
+- directory-api [164]
| +- service-model [183]
| +- org.hibernate.core [175]
| | +- org.ops4j.pax.logging.pax-logging-api [
===== - jdbc =====
karaf@root()> feature:install jdbc 17:51:10
karaf@root()> jdbc:ds-info 17:57:55
Error executing command jdbc:ds-info: argument datasource is required
karaf@root()> jdbc:ds-info jdbc/serviceh2ds 17:58:03
Property │ Value
───────────────┼────────────────────────
driver.version │ 1.3.172 (2013-05-25)
db.version │ 1.3.172 (2013-05-25)
db.product │ H2
url │ jdbc:h2:mem:serviceh2ds
driver.name │ H2 JDBC Driver
username │ DS
karaf@root()> jdbc:ds-list 17:58:18
Name │ Product │ Version │ URL │ Status
─────┼─────────┼─────────┼─────┼───────
karaf@root()> jdbc:tables jdbc/serviceh2ds 17:58:36
TABLE_CAT │ TABLE_NAME │ SELF_REFERENCING_COL_NAME │ TABLE_SCHEM │ TYPE_SCHEM │ TYPE_CAT │ TABLE_TYPE │ REMARKS │ REF_GENERATION │ TYPE_NAME │ SQL
────────────┼───────────────────┼───────────────────────────┼────────────────────┼────────────┼──────────┼──────────────┼─────────┼────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────
SERVICEH2DS │ CATALOGS │
===== - Bundle dependencies =====
Feature can not be resolved, missing dependencies.
Install bundle:
bundle:install mvn:groupId/artefactId/version
bundle_id
Show dependencies:
bundle:tree-show #bundle_id
==== - Declare dependencies ====
* embedded deps: https://stackoverflow.com/a/30532447/707704
* Manifest imports require the bundles containing packages are installed before.
* Bundle installation, exported packages vs. exported services????
* https://ops4j1.jira.com/wiki/spaces/paxurl/pages/3833898/Wrap+Protocol
* Blueprint service, ref, etc
* http://aries.apache.org/documentation/tutorials/blueprinthelloworldtutorial.html
* http://karaf.922171.n3.nabble.com/Multiple-bundles-dependencies-injection-pax-cdi-or-blueprint-td4049756.html
* https://access.redhat.com/documentation/en-us/red_hat_jboss_fuse/6.3/html/deploying_into_apache_karaf/paxcdi
==== - Sample hibernate troubleshooting ====
The error:
Error executing command: Unable to resolve root: missing requirement [root] osgi.identity; osgi.identity=sd-model; type=karaf.feature; version="[1.0.0,1.0.0]"; filter:="(&(osgi.identity=sd-model)(type=karaf.feature)(version>=1.0.0)(version<=1.0.0))"
[caused by: Unable to resolve sd-model/1.0.0: missing requirement [sd-model/1.0.0] osgi.identity; osgi.identity=service-model; type=osgi.bundle;
version="[1.0.0,1.0.0]"; resolution:=mandatory
[caused by: Unable to resolve service-model/1.0.0: missing requirement [service-model/1.0.0] osgi.service;
objectClass=javax.persistence.spi.PersistenceProvider; javax.persistence.provider=org.hibernate.jpa.HibernatePersistenceProvider; effective:=active]]
=== - Disable Required capability ===
* https://issues.apache.org/jira/browse/KARAF-3520
**Only feature 1.3.0**
vim karaf-distribution/target/assembly/etc/org.apache.karaf.features.cfg
#
# Service requirements enforcement
#
# By default, the feature resolver checks the service requirements/capabilities of
# bundles for new features (xml schema >= 1.3.0) in order to automatically installs
# the required bundles.
# The following flag can have those values:
# - disable: service requirements are completely ignored
# - default: service requirements are ignored for old features
# - enforce: service requirements are always verified
#
serviceRequirements=disable
Using command:
karaf@root()> config:edit org.apache.karaf.log
config:property-list
config:property-set serviceRequirements disable
config:update and config:cancel
=== - tBD ===
It looks like persistenceProvider not available.
* https://stackoverflow.com/questions/27203518/karaf-with-hibernate-does-not-start-my-persistence-unit
* https://groups.google.com/forum/#!topic/ops4j/PPc0zDY8bK0
n persistence.xml the persistence provider is set to "org.hibernate.jpa.HibernatePersistenceProvider".
So perhaps there is no suitable persistence provider installed.
You can use "service:list PersistenceProvider" to see which providers are installed.
This is what it shows for me:
[javax.persistence.spi.PersistenceProvider]
-------------------------------------------
javax.persistence.provider = org.hibernate.jpa.HibernatePersistenceProvider
service.id = 601
service.bundleid = 275
service.scope = bundle
Provided by :
hibernate-osgi (275)
The service property "javax.persistence.provider" will have to match the name given in persistence.xml.
So
It should work if you do feature:install hibernate/4.3.6.Final .
=== - Dump install process ===
feature:install --store /tmp/karaf.store sd-model
=== - Header command ===
If I hack a camel feature (I modify the system/org/apache/camel/karaf/apache-camel/2.16.2/apache-camel-2.16.2-features.xml file) and comment the other features it depends on like in this picture:
http://i.imgur.com/IFiIKTq.png
Then I (first refresh the camel feature repo and then) I try to install this feature, the resolver output this kind of error:
http://i.imgur.com/cRhWyuR.png
which only partially covers the issues in the feature...
So usually I install manually all the bundles and inspect the one that won't start with the headers command, and the output is this:
http://i.imgur.com/0LxNEBB.png
headers #bundle_id
When it was possible to use the -c options, I didn't need to install manually each bundle...
=== - bundle dependency=true ===
* http://karaf.922171.n3.nabble.com/features-xml-dependency-quot-true-quot-td3286359.html
===== - Sources =====
* https://karaf.apache.org/manual/latest/#_dump
* http://blog.christianposta.com/osgi/understanding-how-osgi-bundles-get-resolved-part-i/
====== - Karaf Archetype ======
* http://blog.nanthrax.net/2011/12/overview-on-apache-karaf-pax-web-and-camel-archetypes/
* http://repo1.maven.org/maven2/org/apache/karaf/archetypes/
===== - Root maven project =====
mvn archetype:generate \
-DarchetypeGroupId=org.codehaus.mojo.archetypes \
-DarchetypeArtifactId=pom-root \
-DarchetypeVersion=RELEASE
Define value for property 'groupId': : de.gtarc.tutorial.karaf.echo
Define value for property 'artifactId': : echo-project
Define value for property 'version': 1.0-SNAPSHOT: : 1.0
Define value for property 'package': de.gtarc.tutorial.karaf.echo: :
Confirm properties configuration:
groupId: de.gtarc.tutorial.karaf.echo
artifactId: echo-project
version: 1.0
package: de.gtarc.tutorial.karaf.echo
karaf_tutorial]$ ls
echo-project
The other archetype can be generated as following
mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=ARCHETYPE_NAME
Adding parameters:
-DarchetypeVersion=4.0.0 \
-DgroupId=com.mycompany \
-DartifactId=com.mycompany.blueprint \
-Dversion=1.0-SNAPSHOT \
-Dpackage=com.mycompany.blueprint
===== - Karaf assembly / distribution =====
The karaf-assembly-archetype create a Maven project which create a custom Karaf distribution.
It allows you to create your own Karaf distribution. The project downloads a Karaf standard distribution (in tar.gz and zip formats), unpack it, and create a new distribution.
The easiest way to use it is to use the interactive mode:
mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=karaf-assembly-archetype -DarchetypeVersion=2.2.5-SNAPSHOT
===== - Bundle Archetype =====
If basically a bundle is a jar file with some special statement in the MANIFEST, the easiest way to create a bundle is to use the Felix maven-bundle-plugin.
Karaf provides an archetype which prepare a Maven project and provide a bundle Activator (a special callback class when the bundle start/stop).
To generate this project, simply type:
mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=karaf-bundle-archetype -DarchetypeVersion=2.2.5-SNAPSHOT
NB: I think that this archetype should be in Felix (as the same level as maven-bundle-plugin), I will propose a donation to the Felix community.
===== - Blueprint Archetype =====
Blueprint is IoC approach applied to OSGi (it comes from Spring DM in fact). It allows you to avoid to write bundle Activator, ServiceTracker, etc.
Karaf provides a karaf-blueprint-archetype which prepare a Maven project including the maven-bundle-plugin, and a blueprint descriptor with a sample of OSGi service definition:
mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=karaf-blueprint-archetype -DarchetypeVersion=2.2.5-SNAPSHOT
NB: I think that this archetype should be in Aries (as it’s the blueprint implementation used in Karaf), I will propose a donation to the Aries community.
==== In Action ====
* http://wiki.pentaho.com/display/PEOpen/Writing+PDI+Plugin+OSGI+Bundles
* http://ggl-consulting.blogspot.de/2014/02/osgi-bundle-using-blueprint-dymisfied.html
===== - Feature Archetype =====
In Karaf, a feature is an application descriptor, defining all bundles, configurations/configuration files, others features. This features descriptor could be generated by hand (it’s my favorite way, and I guess the recommended one), we also provide a archetype which prepare a project to generate features file regarding the POM dependencies:
mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=karaf-feature-archetype -DarchetypeVersion=2.2.5-SNAPSHOT
===== - Kar Archetype =====
We saw in my previous post a new goal of the features-maven-plugin to create a kar file starting from a features XML. A KAR file is a zip file containing the features XML and all its dependencies.
We also provide an archetype to prepare a Maven project containing a features XML and generate a KAR file:
mvn archetype:generate -DarchetypeGroupId=org.apache.karaf.archetypes -DarchetypeArtifactId=karaf-kar-archetype -DarchetypeVersion=2.2.5-SNAPSHOT
===== Pax-Web Archetypes =====
We also add several archetypes in Pax Web to deal with the web bundle. Charles talk about wab-gwt archetype in his last blog entry (http://cmoulliard.blogspot.com/2011/12/run-google-web-toolkit-2-project-on.html), but I added also two others.
===== Web Bundle Archetype =====
The Web Bundle Archetype create a “special” bundle containing web resources and statements. It creates a Maven project with webapp resources and WebApp Context in the POM:
mvn archetype:generate -DarchetypeGroupId=org.ops4j.pax.web.archetypes -DarchetypeArtifactId=wab-archetype -DarchetypeVersion=1.1.2-SNAPSHOT
===== War Archetype =====
We also provide an archetype to create a Maven project which generate a standard war (that you can deploy “outside” of OSGi) but including OSGi statements in the MANIFEST (which allows you to use OSGi values):
mvn archetype:generate -DarchetypeGroupId=org.ops4j.pax.web.archetypes -DarchetypeArtifactId=war-archetype -DarchetypeVersion=1.1.2-SNAPSHOT
===== Camel Archetypes --> better =====
Camel also provides a set of very useful archetypes, especially:
camel-archetype-blueprint to generate a Maven project with a blueprint XML in which you can define your routes
camel-archetype-component providing a template to create your own Camel component
camel-archetype-dataformat providing a template to create your own Camel data format
camel-archetype-java providing a template with a class in which you can define your routes
camel-archetype-spring to generate a Maven project with a Spring XML in which you can define your routes
**USE THIS** For instance, to create a Camel blueprint Maven project, simply type:
mvn archetype:generate -DarchetypeGroupId=org.apache.camel.archetypes -DarchetypeArtifactId=camel-archetype-blueprint -DarchetypeVersion=2.9-SNAPSHOT
* http://ggl-consulting.blogspot.de/2014/02/osgi-bundle-using-blueprint-dymisfied.html
===== Load & Run: Simple Bundle =====
install mvn:group_id/artefact_id/version
Load and run bundle:
karaf@root> install mvn:com.michaelrice/osgi-demo-next/1.0.0-SNAPSHOT
karaf@root> install file:/var/project/osgi-blueprint-tutorial/hascode-blueprint-bundle/target/hascode-blueprint-bundle-0.0.1.jar
====== - Introductory ======
* https://blog.openshift.com/writing-modular-osgi-applications-using-the-java-virtual-machine-on-openshift/
* https://access.redhat.com/documentation/en-US/Fuse_ESB_Enterprise/7.0/html-single/Product_Introduction/index.html
* http://stackoverflow.com/questions/9430270/enterprise-osgi-frameworks-maturity-comparison-apache-aries-vs-eclipse-gemini
* https://svn.apache.org/repos/asf/aries/slides/
===== - Custom Karaf Distribution =====
* https://karaf.apache.org/manual/latest/#_custom_distributions
Why should we? This custom distribution could contain:
* branding to change the Karaf console look-and-feel
* configuration files (in the etc folder) altered to your requirements
* pre-packaged artifacts in the deploy folder
* a pre-populated system repository (containing your own bundle and features descriptor)
* renamed or specific scripts in the bin folder
* system documentation files
==== - Maven assembly ====
The recommended way to create a Karaf server assembly is to use the karaf-assembly packaging with the karaf-maven-plugin. This assembles a server from the maven dependencies in the project pom. After explanation of the configuration options we present an example.
The Karaf project effectively uses this packaging to assemble the official Karaf distributions, but due to maven limitations we have to simulate rather than use the karaf-assembly packaging.
This packaging creates tar.gz and zip archives containing the assembled server. They are identical except that zip archives don’t unpack with appropriate unix file permissions for the scripts.
==== - Maven dependencies ====
Maven dependencies in a karaf-assembly project can be feature repositories (classifier "features") or kar archives. Feature repositories are installed in the internal "system" Maven structured repository. Kar archives have their content unpacked on top of the server as well as contained feature repositories installed.
The Maven scope of a dependency determines whether its feature repository is listed in the **features service configuration file etc/org.apache.karaf.features.cfg featuresRepositories property**:
compile (default): All the features in the repository (or for a kar repositories) will be installed into the startup.properties. The feature repo is not listed in the features service configuration file.
runtime: feature installation is controlled by , , and elements in the karaf-maven-plugin configuration. The feature repo uri is listed in the features service configuration file.
**Note**: Using runtime, the feature can not be refreshed!!
==== - Plugin configuration ====
Control how features are installed using these elements referring to features from installed feature repositories:
foo - This will result in the feature bundles being listed in startup.properties at the appropriate start level and the bundles being copied into the "system" internal repository. You can use feature_name or feature_name/feature_version formats.
bar - This will result in the feature name added to boot-features in the features service configuration file and all the bundles in the feature copied into the "system" internal repository. You can use feature_name or feature_name/feature_version formats.
baz - This will result in all the bundles in the feature being installed in the "system" internal repository. Therefore at runtime the feature may be installed without access to external repositories. You can use feature_name or feature_name/feature_version formats.
You can also define the libraries shipped in your custom distribution. For instance, it could be interesting if you want to extend your distribution with some JDBC drivers.
The plugin accepts the element where you can add containing the URL of the library. For instance:
mvn:org.postgresql/postgresql/9.3-1102-jdbc41;type:=endorsed
===== - Development Tips =====
* https://stackoverflow.com/questions/24791950/how-to-work-with-frequent-local-snapshot-bundle-deployments-on-karaf
* http://blog.christianposta.com/osgi/understanding-how-osgi-bundles-get-resolved-part-i/
====== - Bundle Activation ======
* http://blog.knowhowlab.org/2010/10/osgi-tutorial-4-ways-to-activate-code.html
* http://www.hascode.com/2012/04/wiring-made-easy-using-osgi-blueprint-and-apache-karaf/
* http://felix.apache.org/documentation/tutorials-examples-and-presentations/apache-felix-osgi-tutorial.html
* http://www.kevinboone.net/osgitest.html
* https://wiki.opendaylight.org/view/Using_Blueprint
====== - HttpService ======
* http://felix.apache.org/documentation/subprojects.html
* http://felix.apache.org/documentation/subprojects/apache-felix-http-service.html
* http://aries.apache.org/modules/samples/blog-sample.html
===== Pax Web =====
* Pax Web: http://ops4j.github.io/pax/web/4.x/index.html#_configuration
* war extension / whiteboard extension
===== Aries =====
Top of osgi container, providing enterprise services.
http://aries.apache.org/modules/samples/blog-sample.html
===== Rest CXF =====
* http://deemson.blogspot.de/2013/09/restful-web-services-in-osgi-container.html
===== - Angular =====
* whiteboard: http://www.modio.io/angularjs-using-the-http-whiteboard-service/
====== Datasource ======
* Config datasource: https://ops4j1.jira.com/wiki/display/PAXJDBC/Create+DataSource+from+config
* bundle