编程语言
首页 > 编程语言> > Java-NetBeans平台教程问题

Java-NetBeans平台教程问题

作者:互联网

我正在阅读《 Netbeans平台快速入门》教程(http://platform.netbeans.org/tutorials/nbm-quick-start.html),并且我不太清楚“使用查找的模块化应用程序”部分中的第六部分:

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.

有人知道我应该在哪个模块中设置对实用程序API模块的依赖吗?
因为当我在MyFilter中设置依赖项时,编译器告诉我它“找不到符号”.

解决方法:

您需要使MyFilter项目依赖于实用程序API模块,并且需要从以下位置更改代码

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();
    }

}

进入

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();
    }

}

注意:如果首先添加模块依赖项,则可以利用“源”菜单中的“修复导入”项(CTRL-SHIFT-I / Clover-SHIFT-I)自动处理第二个依赖项.

标签:utilities,platform,netbeans,java,openide
来源: https://codeday.me/bug/20191106/2001022.html