Andriy Drozdyuk
Andriy Drozdyuk

Reputation: 61091

bndtools Activator bundle

How can I create a simple bundle with an Activator in bndtools? It keeps saying that:

The JAR is empty: The instructions for the JAR named com.myproj did not cause any content to be included, this is likely wrong  bnd.bnd /com.myproj Unknown Bndtools Problem Marker
Unused Private-Package instructions, no such package(s) on the class path: [com.myproj] bnd.bnd /com.myproj Unknown Bndtools Problem Marker

The way I create this project in Eclipse is:

  1. Create new "Bndtools OSGi project"
  2. Right click, configure - Convert to Maven project
  3. Create Activator.java in package com.myproj.
  4. Add com.myproj to private packages
  5. Set activator to com.Activator

Here is my bnd file:

Bundle-Activator: com.myproj.Activator
Private-Package: com.myproj

My generated jar is empty. Any tips?

P.S.: Here is my eclipse project (exported as a zip-archive) in case it sheds any light on things: https://dl.dropbox.com/u/9162958/scraper.zip

Upvotes: 1

Views: 2623

Answers (2)

Viliam Simko
Viliam Simko

Reputation: 1841

My setup:

  • Eclipse Luna 4.4.0 (20140612-0600)
  • Bndtools 2.3.0.REL-20140510-023245

Here is how I made it work:

  1. I downloaded you exported scraper.zip.
  2. Created and empty workspace in Eclipse.
  3. Imported your project from the ZIP archive into the empty workspace.
  4. The default cnf project was automatically created.
  5. By default, bnd is configured to use the bin directory for compiled *.class files while your Eclipse project is configured to use target/classes. Therefore, I had to change this settings in cnf/build.bnd by adding a single line:
########################
## BND BUILD SETTINGS ##
########################
bin: target/classes
  1. Now, after cleaning and rebuilding the project, bnd creates generated/scraper.jar that contains your Activator.class.

Notes:

  • You could also adapt your project configuration to use the bin directory instead of target/classes but I assume that you will use Maven later on.
  • When using bndtools, it sometimes helps when you start with an empty workspace and import your projects one-by-one.
  • There is a bug in bndtools 2.4 which causes some problems if there are multiple source directories per project. Therefore, I'm still using version 2.3

Upvotes: 1

Peter Kriens
Peter Kriens

Reputation: 15372

My guess is that "Convert to Maven project" is the trouble. This likely has changed the Eclipse classpath for the project from the bnd default bin folder to 'target/classes'. Can you confirm that it works without converting to maven?

bnd can work with other places for the bin folder, you must set the ${bin} property (preferably in cnf/build.bnd). There are some writeups how to use bndtools with maven. The reason that bnd does not follow Eclipse's settings here is that they are not available without Eclipse and a design goal of bnd is that it builds anywhere: the bnd file must therefore be the final arbiter of information.

Anyway one more tip ... activators are not the right way to build OSGi builds since they are an evil singleton. Declarative services is far superior and we should actually have used a similar mechanism when we designed OSGi.

Upvotes: 3

Related Questions