【问题标题】:Maven Netbeans Application does not find ServiceProviderMaven Netbeans 应用程序找不到 ServiceProvider
【发布时间】:2017-06-13 13:20:37
【问题描述】:

设置: 在我们公司,我尝试将基于 Ant 的 Netbeans 应用程序迁移到 Maven。 我有一个基于 Maven 的 Netbeans 平台应用程序和两个包含 Netbeans 模块的 Maven 模块 POM 项目。

|API (POM project)
 |-APIModule
  |-MyService.java
|Implementation (POM project)
 |-ImplModule (dependency on APIModule)
  |-MyServiceProvider.java (implements MyService)
|Application (Maven Netbeans Platform Application) (dependency on API and Implementation)
 |-branding
 |-netbeans-app (the application)
 |-viewer
  |-MyViewer.java (calls Lookup.getDefault().lookup(MyService.class)

API 和 Implementation 使用 <packaging>pom</packaging> 构建,依赖项使用声明

    <dependencies>
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>mavenprojectapi</artifactId>
            <version>${project.version}</version>
            <type>pom</type>
        </dependency>
    </dependencies>

这样,如果我不想再坚持使用 Netbeans 平台,我可以轻松地在 API 部分中替换服务的实现,并构建一个新的 UI。

问题:在 MyViewer 中,我调用 Lookup.getDefault().lookup(MyService.class)

但它没有找到 MyService 的实现。

我知道@ServiceProvider 会在显式声明的情况下找到实现(例如参见here),但这不是我想要的。

问题:如何找到通过 Lookup 和 ServiceProvider在其他模块套件中定义的服务实现

更新:似乎传递依赖项没有从实施项目中加载。我能做的是定义一个 Netbeans 聚合模块,该模块对所有实现模块具有显式依赖关系,并将其声明为我的应用程序中的直接依赖关系。这样就可以加载传递依赖项并找到 ServiceProviders。

想要不过是在基于 Ant 的项目中复制“导入集群”功能。 official NBM plugin documentation 中描述了目标,集群是为单个模块构建的,但我不知道访问它们的方法。有什么想法吗?

【问题讨论】:

    标签: java maven netbeans


    【解决方案1】:

    将 Implementation 模块的模块类型更改为 eager。

    <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>nbm-maven-plugin</artifactId> 
        ...
        <configuration>
            <moduleType>eager</moduleType>
            ...
        </configuration>
    </plugin>
    

    【讨论】:

    • 遗憾的是这并没有解决问题。我编辑并更新了我的问题。
    猜你喜欢
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多