gpt4 book ai didi

java - netbeans平台教程问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:29:04 26 4
gpt4 key购买 nike

我正在阅读 Netbeans 平台快速入门教程 ( http://platform.netbeans.org/tutorials/nbm-quick-start.html ),但我没有清楚地理解“使用查找的模块化应用程序”部分的第 6 部分,提示:

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.

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

最佳答案

您需要使 MyFilter 项目依赖于 Utilities 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) 自动处理第二个。

关于java - netbeans平台教程问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2382726/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com