Maven SCR插件-不生成OSGI-INF文件夹 [英] Maven SCR Plugin - Not generating OSGI-INF folder

查看:87
本文介绍了Maven SCR插件-不生成OSGI-INF文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been having trouble getting my SCR plugin working. I have searched as much as I could bur only found examples that were not similar to the structure I am required to use. Snippets of POMs below. These are pretty much the default generated by the CQ project archetype. All dependencies are there, so it is probably not that. Here is the output of the build:

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 ---.看来,即使注释存在于类中,它也不会生成任何东西.

The key part of the output is the [INFO] --- maven-scr-plugin:1.7.4:scr (generate-scr-descriptor) @ project-bundle ---. It appears that it is not generating anything even though the annotations exist on the class.

父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>,如果是这样,我可以通过将org将maven-scr-plugin升级到1.9.0来解决此问题. apache.felix.scr.annotations @ 1.7.0

I'm guessing you're using <packaging>bundle</packaging>, if so I got this working by upgrading maven-scr-plugin to 1.9.0, with org.apache.felix.scr.annotations @ 1.7.0

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

I put a tarball of a working version here: https://dl.dropboxusercontent.com/u/2465717/com.stackoverflow.osgi.scr.tgz

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

Note: you can enable the Eclipse m2e lifecycle mapping - it works well (Juno SR2), generating SCR component errors in the normal Problems console. Change the action <ignore/> to:

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

此外,虽然规范指出SCR运行时将搜索重载的de/activate方法-作为个人喜好,我将在相应方法上使用@ Activate,@ Deactive和@Modified来使意图明确(在代码和生成的XML中) .但是每个人都有自己的想法.

Also while the spec indicates the SCR runtime will search for overloaded de/activate methods - as personal preference I would use @Activate, @Deactive and @Modified on the respective methods to make the intent explicit (in code and generated XML). But each to their own.

这篇关于Maven SCR插件-不生成OSGI-INF文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆