views:

244

answers:

2

I am reading the Netbeans Platform Quick Start tutorial (http://platform.netbeans.org/tutorials/nbm-quick-start.html), and I do not clearly understand the 6th part in the section "A Modular Application Using Lookup", the TIP:

At compile time, the @ServiceProvider annotation will create a META-INF/services folder with a file that registers your implementation of the TextFilter interface, following the JDK 6 ServiceLoader mechanism. You need to set a dependency on the Utilities API module, which provides the ServiceProvider annotation.

Does anybody know in which module I should set dependency to Utilities API module? Because when I set the dependency in MyFilter, the compiler tells me that it "cannot find symbol".

A: 

I got it, I used older version of netBeans that not support that. This is available since 6.7 version

joseph
I never would have thought of that.
vkraemer
+1  A: 

You need to make the MyFilter project dependent on the Utilities API module AND you need to change the code from

package org.demo.myfilter;

import org.demo.textfilter.TextFilter;

@ServiceProvider(service=TextFilter.class)
public class UpperCaseFilter implements TextFilter {

    public String process(String s) {
        return s.toUpperCase();
    }

}

into

package org.demo.myfilter;

import org.demo.textfilter.TextFilter;
import org.openide.util.lookup.ServiceProvider;

@ServiceProvider(service=TextFilter.class)
public class UpperCaseFilter implements TextFilter {

    public String process(String s) {
        return s.toUpperCase();
    }

}

Note: if you add the module dependency first, you can leverage the Fix Imports item from the Source menu (CTRL-SHIFT-I/Clover-SHIFT-I) to take care of the second one automatically.

vkraemer