0

I am trying to configure how packages are imported/exported by the maven-bundle-plugin by specifying the * wildcard. The config below results in no package being exported or imported...

Anyone has any clue?

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>osgi.org.springframework.batch</groupId>
    <artifactId>spring-batch-core</artifactId>
    <version>2.1.8.RELEASE</version>
     <packaging>bundle</packaging>
    <dependencies>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-core</artifactId>
            <version>2.1.8.RELEASE</version>
            <scope>compile</scope>
            <optional>true</optional>
        </dependency>
    </dependencies>
    <build>
        <defaultGoal>install</defaultGoal>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>1.7.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <includes>
                                    <include>org.springframework.batch:spring-batch-core</include>
                                </includes>
                            </artifactSet>
                            <filters>
                                <filter>
                                    <artifact>org.springframework.batch:spring-batch-core</artifact>
                                    <excludes>
                                        <exclude>**</exclude>
                                    </excludes>
                                </filter>
                            </filters>
                            <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
                            <createDependencyReducedPom>true</createDependencyReducedPom>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.7</version>
                <extensions>true</extensions>
                <configuration>
                    <instructions>
                        <Bundle-SymbolicName>osgi.org.springframework.batch</Bundle-SymbolicName>
                        <Export-Package>*</Export-Package>
                        <Import-Package>*</Import-Package>
                    </instructions>
                    <unpackBundle>true</unpackBundle>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

EDIT: The exact message I get is

karaf@root> package:import  181
spring-batch-core (181): No active imported packages.

because the bundle is not active.

EDIT: When I start the bundle I get this:

karaf@root> osgi:start 181
org.osgi.framework.BundleException: Unresolved constraint in bundle osgi.org.springframework.batch [181]: Unable to resolve 181.0: missing requirement
 [181.0] package; (package=bsh)

EDIT: If I just use the spring batch core, I systematically get this error on startup:

karaf@root> Exception in thread "SpringOsgiExtenderThread-2" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'j
obRepository': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/HierarchicalStreamDri
ver
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1422)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationCont
ext.java:69)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.ja
va:355)
        at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplication
Context.java:320)
        at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(Dependen
cyWaiterApplicationContextExecutor.java:132)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/HierarchicalStreamDriver
        at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao.afterPropertiesSet(JdbcExecutionContextDao.java:169)
        at org.springframework.batch.core.repository.support.JobRepositoryFactoryBean.createExecutionContextDao(JobRepositoryFactoryBean.java:206)
        at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean.getTarget(AbstractJobRepositoryFactoryBean.java:190)
        at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean.initializeProxy(AbstractJobRepositoryFactoryBean.java:17
9)
        at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean.afterPropertiesSet(AbstractJobRepositoryFactoryBean.java
:186)
        at org.springframework.batch.core.repository.support.JobRepositoryFactoryBean.afterPropertiesSet(JobRepositoryFactoryBean.java:157)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479
)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1419)
        ... 14 more
Caused by: java.lang.ClassNotFoundException: com.thoughtworks.xstream.io.HierarchicalStreamDriver not found by org.springframework.batch.core [85]
        at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787)
        at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71)
        at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1768)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 22 more
Exception in thread "SpringOsgiExtenderThread-4" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobRepository
': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/HierarchicalStreamDriver
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1422)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:518)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:293)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:290)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:192)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationCont
ext.java:69)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.ja
va:355)
        at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplication
Context.java:320)
        at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(Dependen
cyWaiterApplicationContextExecutor.java:132)
        at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NoClassDefFoundError: com/thoughtworks/xstream/io/HierarchicalStreamDriver
        at org.springframework.batch.core.repository.dao.JdbcExecutionContextDao.afterPropertiesSet(JdbcExecutionContextDao.java:169)
        at org.springframework.batch.core.repository.support.JobRepositoryFactoryBean.createExecutionContextDao(JobRepositoryFactoryBean.java:206)
        at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean.getTarget(AbstractJobRepositoryFactoryBean.java:190)
        at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean.initializeProxy(AbstractJobRepositoryFactoryBean.java:17
9)
        at org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean.afterPropertiesSet(AbstractJobRepositoryFactoryBean.java
:186)
        at org.springframework.batch.core.repository.support.JobRepositoryFactoryBean.afterPropertiesSet(JobRepositoryFactoryBean.java:157)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1479
)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1419)
        ... 14 more
Caused by: java.lang.ClassNotFoundException: com.thoughtworks.xstream.io.HierarchicalStreamDriver not found by org.springframework.batch.core [85]
        at org.apache.felix.framework.ModuleImpl.findClassOrResourceByDelegation(ModuleImpl.java:787)
        at org.apache.felix.framework.ModuleImpl.access$400(ModuleImpl.java:71)
        at org.apache.felix.framework.ModuleImpl$ModuleClassLoader.loadClass(ModuleImpl.java:1768)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        ... 22 more

EDIT:

karaf@root> package:export 57
    ID Packages
    57 com.thoughtworks.xstream; version=0.0.0
    57 com.thoughtworks.xstream.alias; version=0.0.0
    57 com.thoughtworks.xstream.annotations; version=0.0.0
    57 com.thoughtworks.xstream.converters; version=0.0.0
    57 com.thoughtworks.xstream.converters.basic; version=0.0.0
    57 com.thoughtworks.xstream.converters.collections; version=0.0.0
    57 com.thoughtworks.xstream.converters.enums; version=0.0.0
    57 com.thoughtworks.xstream.converters.extended; version=0.0.0
    57 com.thoughtworks.xstream.converters.javabean; version=0.0.0
    57 com.thoughtworks.xstream.converters.reflection; version=0.0.0
    57 com.thoughtworks.xstream.core; version=0.0.0
    57 com.thoughtworks.xstream.core.util; version=0.0.0
    57 com.thoughtworks.xstream.io; version=0.0.0
    57 com.thoughtworks.xstream.io.binary; version=0.0.0
    57 com.thoughtworks.xstream.io.copy; version=0.0.0
    57 com.thoughtworks.xstream.io.json; version=0.0.0
    57 com.thoughtworks.xstream.io.path; version=0.0.0
    57 com.thoughtworks.xstream.io.xml; version=0.0.0
    57 com.thoughtworks.xstream.io.xml.xppdom; version=0.0.0
    57 com.thoughtworks.xstream.mapper; version=0.0.0
    57 com.thoughtworks.xstream.persistence; version=0.0.0
balteo
  • 23,602
  • 63
  • 219
  • 412

1 Answers1

1

Why do you need o do this? The spring-batch-core is already an OSGi ready bundle, isn't it? Check the MANIFEST.MF from that jar. I just looked up the 2.0.4.RELEASE for spring-batch and from what I see it is already a bundle.

Eugene
  • 117,005
  • 15
  • 201
  • 306
  • I have edited my post to show you the error I get when I use the jar/bundle from springsource... – balteo Aug 14 '12 at 12:03
  • This is the relevant line: `Caused by: java.lang.ClassNotFoundException: com.thoughtworks.xstream.io.HierarchicalStreamDriver not found by org.springframework.batch.core [85]` – balteo Aug 14 '12 at 12:12
  • 1
    @balteo do you have a jar that actually exports this class? There are commands under karaf that will tell if at least some bundle exports a package/class or not. – Eugene Aug 14 '12 at 12:14
  • I do have a bundle that exports this package. Can you be more specific regarding the Karaf command you are referring to? – balteo Aug 14 '12 at 12:20
  • @balteo http://mail-archives.apache.org/mod_mbox/karaf-user/201206.mbox/%3C4FE3FB72.7040302@nanthrax.net%3E – Eugene Aug 14 '12 at 12:24
  • Eugene: Thanks. As you can see from my post I already use the package:export/import command. What I am specifically looking for is a command to **set** the packages imported/exported... – balteo Aug 14 '12 at 12:28
  • @balteo "I do have a bundle that exports this package" how do you know? What command did u run and what was it's output. Because from the logs Karaf can't see this package. – Eugene Aug 14 '12 at 12:35
  • I ran package:export 57 (57 being the xstream bundle). I am adding the results of this command to my post. Bear with me... – balteo Aug 14 '12 at 12:42
  • I see the problem thus: `com.thoughtworks.xstream.io` is exported by 57 (being xstream) but not imported by 85 (being spring batch core) hence my problem... – balteo Aug 14 '12 at 12:45
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/15337/discussion-between-eugene-and-balteo) – Eugene Aug 14 '12 at 12:52