Maven SCR 插件 - 不生成 OSGI-INF 文件夹

2024-01-10

我的 SCR 插件无法正常工作。我已经尽可能多地进行了搜索,但只找到了与我需要使用的结构不相似的示例。下面是 POM 的片段。这些几乎是 CQ 项目原型生成的默认值。所有依赖项都在那里,所以可能不是这样。这是构建的输出:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building project Bundle 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ project-bundle ---
[INFO] Deleting C:\project-path\target
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ bundle ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\project-path\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ project-bundle ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 4 source files to C:\project-path\target\classes
[INFO] 
[INFO] --- maven-scr-plugin:1.7.4:scr (generate-scr-descriptor) @ project-bundle ---
[INFO] 
[INFO] --- maven-resources-plugin:2.5:testResources (default-testResources) @ project-bundle ---
[debug] execute contextualize
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\project-path\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ project-bundle ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:9c6abc2:test (default-test) @ project-bundle ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-bundle-plugin:2.3.6:bundle (default-bundle) @ project-bundle ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ project-bundle ---
[INFO] Installing C:\project-path\target\project-bundle-1.0-SNAPSHOT.jar to C:\user-path\.m2\repository\com\project\cq\project-bundle\1.0-SNAPSHOT\project-bundle-1.0-SNAPSHOT.jar
[INFO] Installing C:\project-path\pom.xml to C:\user-path\.m2\repository\com\project\cq\project-bundle\1.0-SNAPSHOT\project-bundle-1.0-SNAPSHOT.pom
[INFO] 
[INFO] --- maven-bundle-plugin:2.3.6:install (default-install) @ project-bundle ---
[INFO] Installing com/project/cq/project-bundle/1.0-SNAPSHOT/project-bundle-1.0-SNAPSHOT.jar
[INFO] Writing OBR metadata
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.189s
[INFO] Finished at: Wed Apr 17 10:29:17 CDT 2013
[INFO] Final Memory: 15M/221M
[INFO] ------------------------------------------------------------------------

输出的关键部分是[INFO] --- maven-scr-plugin:1.7.4:scr (generate-scr-descriptor) @ project-bundle ---。即使类上存在注释,它似乎也不会生成任何内容。

父 POM 片段:

<build>
    <pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-scr-plugin</artifactId>
                <version>1.7.4</version>
            </plugin>
            <plugin>
                <groupId>org.apache.felix</groupId>
                <artifactId>maven-bundle-plugin</artifactId>
                <version>2.3.6</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <!-- use version 2.3.2 to have java 1.5 as the default -->
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
                <version>2.3.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.5</version>
            </plugin>
            <plugin>
                <groupId>org.apache.sling</groupId>
                <artifactId>maven-sling-plugin</artifactId>
                <version>2.0.6</version>
            </plugin>
            <plugin>
                <groupId>com.day.jcr.vault</groupId>
                <artifactId>content-package-maven-plugin</artifactId>
                <version>0.0.13</version>
            </plugin>
            <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the 
                Maven build itself. -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.felix</groupId>
                                    <artifactId>maven-scr-plugin</artifactId>
                                    <versionRange>[1.7.4,)</versionRange>
                                    <goals>
                                        <goal>scr</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <ignore />
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>
</build>

子 POM 片段:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-scr-plugin</artifactId>
            <extensions>true</extensions>
            <executions>
                <execution>
                    <id>generate-scr-descriptor</id>
                    <goals>
                        <goal>scr</goal>
                    </goals>
                </execution>
            </executions>
       </plugin>
       <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>project.project-bundle</Bundle-SymbolicName>
                </instructions>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.sling</groupId>
            <artifactId>maven-sling-plugin</artifactId>
            <configuration>
                <slingUrl>http://${crx.host}:${crx.port}/apps/project/install</slingUrl>
                <usePut>true</usePut>
            </configuration>
        </plugin>
    </plugins>
</build>

正在构建的代码:

package com.project.cq.examples.dictionaryservice.impl;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.ComponentContext;

import com.project.cq.examples.dictionaryservice.DictionaryService;

@Component(immediate = true, metatype = true, label = "Service Implementation", description = "The implementation for the Service")
@Service
public class DictionaryServiceServletImpl implements DictionaryService {

    @Property(label = "Words", description = "The list of words.")
    private static final String PROP_WORDS = "words";

    // The set of words
    private String[] words;
    private boolean active;
    private boolean modified;

    @Override
    public boolean checkWord(String word) {
        word = word.toLowerCase();

        // This is very inefficient
        for (int i = 0; i < words.length; i++) {
            if (words[i].equals(word)) {
                return false;
            }
        }
        return true;
    }

    protected void activate(ComponentContext context) {
        active = true;
        dictionary = (String[]) context.getProperties().get(
                PROP_WORDS);
    }

    protected void deactivate(ComponentContext context) {
        dictionary = null;
        active = false;
    }

    protected void modified(ComponentContext context) {
        modified = true;
        dictionary = (String[]) context.getProperties().get(
                PROP_WORDS);
    }
}

任何帮助是极大的赞赏。


我猜你正在使用<packaging>bundle</packaging>,如果是这样,我通过将 maven-scr-plugin 升级到 1.9.0 并使用 org.apache.felix.scr.annotations @ 1.7.0 来实现此工作

我在这里放置了一个工作版本的 tarball:https://dl.dropboxusercontent.com/u/2465717/com.stackoverflow.osgi.scr.tgz https://dl.dropboxusercontent.com/u/2465717/com.stackoverflow.osgi.scr.tgz

注意:您可以启用 Eclipse m2e 生命周期映射 - 它运行良好 (Juno SR2),在正常问题控制台中生成 SCR 组件错误。改变action <ignore/> to:

<action>
        <execute>
                <runOnIncremental>true</runOnIncremental>
                <runOnConfiguration>true</runOnConfiguration>
        </execute>
</action>

此外,虽然规范表明 SCR 运行时将搜索重载的 de/activate 方法 - 作为个人偏好,我会在相应的方法上使用 @Activate、@Deactive 和 @Modified 来使意图明确(在代码和生成的 XML 中)。但各有各的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Maven SCR 插件 - 不生成 OSGI-INF 文件夹 的相关文章

随机推荐

  • Protractor:Protractor 中的ignoreSynchronization 和async/await 有什么区别

    我是量角器的新手 我正在做测试来熟悉它 在这里 我遇到了一个问题 我无法区分ignoreSynchronization和async await方法 我有 3 个区块来测试它们 第一个是量角器自己的异步功能 it without await
  • https 在 Fiddler 和 .NET 中给出 ERR_CONNECTION_RESET

    谁能向我解释一下为什么在 Chrome 中输入此链接 https secure malindoair com MalindoAirCIBE OnlineBooking aspx https secure malindoair com Mal
  • MVC3 默认模板在哪里存储用户帐户信息?

    你能告诉我当我注册新帐户时 asp net mvc3默认模板将登录信息存储在哪里吗 它在调试模式下本地运行 在没有安装SQLExpress的情况下 注册功能根本不起作用 由于我安装了它 所以我可以使用注册 登录功能 但我在SQLExpres
  • stdin 上的 close/fclose 是否保证正确?

    似乎以下调用执行了您所期望的操作 关闭流并不允许任何进一步的输入 等待流上的输入的任何操作都会返回错误 但它是否保证在所有编译器 平台上都是正确的 close fileno stdin fclose stdin fclose stdin 导
  • .val() 未从输入获取更新值

    我有两个输入字段 我试图通过单击按钮使用 jquery 获取它们的值 这似乎是一个非常简单的操作 但我一生都无法让它发挥作用 这是代码片段 Name
  • 累加值,例如通过扫描,但可以随着时间的推移重置累加器

    我有一个可观察的 obs1 它代表一段时间内的数字流 我需要累积这些数字的总和并逐步发出它 即 很长一段路要说我需要使用scan操作员 然后是第二个 Observable obs2 代表某种 重置时间 换句话说 当obs2发出 我必须重置我
  • Opengl 深度缓冲区和剔除

    OpenGL 中使用背面剔除和深度缓冲区有什么区别 背面剔除是指 OpenGL 确定哪些面背对观看者 因此不可见 想象一个立方体 无论你如何旋转立方体 三个面始终是不可见的 找出这些面是哪些面 将它们从要绘制的多边形列表中删除 这样您就将绘
  • 打开 QDialog 并保存最后的状态

    我正在尝试打开一个QDialog from a QMainWindow 并且在关闭 QDialog之后 如果我需要再次打开它 它必须打开并显示与我关闭它时相同的信息 这是代码QMainWindow class A QMainWindow d
  • 从 Azure DevOps Python Artifacts feed 进行 pip 安装不起作用

    当我尝试从 Azure DevOps Artifacts feed 安装包时 出现错误 Looking in indexes https pypi org simple https pkgs dev azure com company co
  • 如何将可变数量的参数传递给 lambda 函数

    我正在尝试将可变数量的参数传递给 lambda 函数 lambda 函数中接受可变数量参数的原型是什么 我应该写一个命名函数而不是 lambda 吗 std once flag flag template
  • 适用于所有 Android 设备的 Android Badger

    你好 我有 android 应用程序 我需要将 badger 添加到应用程序启动器我在互联网上搜索并找到了这个库 compile me leolin ShortcutBadger 1 1 4 aar 可以工作 但不适用于我在三星和 HTC
  • C 中的简单 lua_yield 无法从 Lua 正确恢复

    我刚刚开始深入研究 lua 协程与 C 我对我认为应该是我能想到的最简单的例子有疑问 The C include
  • Table2excel 插件不起作用

    我正在开发一个仪表板应用程序 我想实现 下载表为 xls 功能 在此链接上您可以看到表格的样子仪表板 http pasteboard co p82eqze png 我找到了一个library https github com rainabb
  • 按 lubridate 日期 %within% 间隔连接数据框

    我一直在练习和学习使用包含以下内容的列来处理 R 数据框lubridate数据类型 例如我的示例问题其他问题 https stackoverflow com questions 51407177 r lubridate split dura
  • Hadoop start-all.sh错误:没有这样的文件或目录

    成功创建名称节点后 我在尝试启动名称节点时遇到了这个问题 对我来说 它似乎试图记录到一个不存在的文件 如何更改设置以将脚本日志定向到正确的目录 bash 3 2 start all sh starting namenode logging
  • 如何在 Docker 第 3 部分教程中使用curl -4 http://localhost?

    使用 Docker 教程我被困在这部分 https docs docker com get started part3 run your new load balanced app https docs docker com get sta
  • 读取 Hadoop ArrayWritable 中包装的值

    我是 Hadoop 和 Java 的新手 我的映射器输出文本和 Arraywritable 我在读取 ArrayWritable 值时遇到问题 Unbale 将 get 值转换为整数 附上映射器和减速器代码 有人可以帮我纠正我的减速器代码以
  • 计算 PHP 数组中的日期

    我有这个数组 Array 0 gt Array x gt 2016 04 19 1 gt Array x gt 2016 05 25 2 gt Array x gt 2016 05 26 3 gt Array x gt 2016 05 27
  • std::tuple 用于不可复制和不可移动的对象

    我有一门删除了复制和移动向量的课程 struct A A int a data a A std cout lt lt A lt lt this lt lt lt lt data lt lt std endl A A const obj de
  • Maven SCR 插件 - 不生成 OSGI-INF 文件夹

    我的 SCR 插件无法正常工作 我已经尽可能多地进行了搜索 但只找到了与我需要使用的结构不相似的示例 下面是 POM 的片段 这些几乎是 CQ 项目原型生成的默认值 所有依赖项都在那里 所以可能不是这样 这是构建的输出 SLF4J Fail