Rüdiger Herrmann
Rüdiger Herrmann

Reputation: 21025

How to import package from bundle with Bndtools

I was following this Bndtools tutorial http://bndtools.org/tutorial.html to implement a simple greeting service.

First, I created this interface in bundle org.example.api:

package org.example.api;

public interface Greeting {
  String sayHello( String name );
}

Then a service that implements the above interface in bundle org.example.impl:

package org.example.impl;

import org.osgi.service.component.annotations.Component;

@Component
public class GreetingComponent implements Greeting {
  public String sayHello( String name ) {
    return "Hello " + name;
  }
}

Of course, the type Greeting cannot be resolved. And here comes my question: what is the designated way to add the package import declaration to the impl bundle? I am aware that I could manually edit bnd.bnd of org.example.impl to include the necessary package in the -buildpath directive.

But that is rather inconvenient: memorize the package name, navigate to the appropriate bnd file, edit the directive, save. Isn't here a more convenient way to add the missing import?

I was looking for something like a quick fix (Ctrl+1) but that doesn't seem to exist.

Upvotes: 2

Views: 717

Answers (1)

Peter Kirschner
Peter Kirschner

Reputation: 927

You have to maintain the Build Path/Bnd Bundle Path and APIs via the bnd.bnd Bnd Project Editor. Take care to open the correct editor. File association *.bnd is in some Eclipse instances associated to Text Editor, instead of Bnd Bundle Editor. Open the bnd file with Bnd Project Editor and add the bundles for the build path either via

  1. Drag-and-Drop from Repository view
  2. Build Tab - Build Path Section and Button + with search functionality
  3. Source Tab is also an option

IMHO DnD is easiest and fastest way ;-)

Upvotes: 0

Related Questions