Milla
Milla

Reputation: 503

Spring based bundle on apache karaf doesn't work

I am creating a spring based bundle with maven with the following command

mvn archetype:generate -DarchetypeGroupId=org.apache.camel.archetypes -DarchetypeArtifactId=camel-archetype-spring -DarchetypeVersion=2.15.3 -DgroupId=osgiSpring -DartifactId=osgiSpring -Dversion=1.0-SNAPSHOT -Dpackage=osgiSpring

Then i imported this maven project into eclipse and just change the 'camel-context.xml' to

<?xml version="1.0" encoding="UTF-8"?>
<!--

 Copyright 2005-2014 Red Hat, Inc.

 Red Hat 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

    http://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.

    -->
    <beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

  <camelContext xmlns="http://camel.apache.org/schema/spring">
  <route>
    <from uri="file:C:\input"/>
    <to uri="file:C:\output"/>
  </route>
</camelContext>

</beans>

After that I built it with 'mvn package' and then I copied the generated jar into Apache Karafs' deploy folder but karaf doesn't seem to recognize this bundle.

When I run it with 'mvn:camel run' it works just fine.

It also worked with a non spring based bundle with an Activator.

Upvotes: 1

Views: 674

Answers (1)

jnupponen
jnupponen

Reputation: 745

Your problem is that camel-archetype-spring generates pom.xml with just camel-maven-plugin which as you noticed allows you to run your code via 'mvn camel:run'. However, it does not generate proper OSGi manifest so Karaf won't recognise it as OSGi bundle.

Solution: Add maven-bundle-plugin like this:

<plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <version>2.3.7</version>
    <extensions>true</extensions>
</plugin>

and set packaging to bundle like this:

<packaging>bundle</packaging>

You can read about other configuration options available to maven-bundle-plugin here. I suggest you check your jar file's META-INF/MANIFEST.MF file before and after you make these changes so you get the grasp of what changes there.

Upvotes: 2

Related Questions