netbeans平台教程问题

发布于 2024-08-24 02:07:38 字数 521 浏览 5 评论 0原文

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

在编译时,@ServiceProvider 注释将创建一个 META-INF/services 文件夹,其中包含一个注册 TextFilter 接口实现的文件,遵循 JDK 6 ServiceLoader 机制。您需要设置对 Utilities API 模块的依赖,该模块提供 ServiceProvider 注释。

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

痴骨ら 2024-08-31 02:07:38

您需要使 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) 自动处理第二个。

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.

终难愈 2024-08-31 02:07:38

我明白了,我使用的是不支持该功能的旧版本 netBeans。从 6.7 版本开始可用

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文