简体   繁体   中英

netbeans platform tutorial problem

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".

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM