5

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);
    }
}

どんな助けでも大歓迎です。

4

3 に答える 3

7

を使用していると思います。<packaging>bundle</packaging>もしそうなら、org.apache.felix.scr.annotations @ 1.7.0 を使用して maven-scr-plugin を 1.9.0 にアップグレードすることで、これが機能するようになりました。

ここに作業バージョンの tarball を置きます: https://dl.dropboxusercontent.com/u/2465717/com.stackoverflow.osgi.scr.tgz

注: Eclipse m2e ライフサイクル マッピングを有効にできます。正常に動作し (Juno SR2)、通常の問題コンソールで SCR コンポーネント エラーが生成されます。を次のように変更action <ignore/>します。

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

また、仕様では、SCR ランタイムがオーバーロードされた de/activate メソッドを検索することを示していますが、個人的な好みとして、それぞれのメソッドで @Activate、@Deactive、および @Modified を使用して、(コードおよび生成された XML で) 意図を明示的にします。しかし、それぞれ独自のものです。

于 2013-04-17T17:30:20.613 に答える
1

私はあなたに提案します

  • の最新バージョンにアップグレードするmaven-scr-plugin
  • でデバッグを生成します-Xmvn -X compile
于 2013-04-22T08:08:11.717 に答える
0

1.9.0 へのアップグレードはうまくいきました。プラグイン v1.7.4 は記述子を生成しないということですか。なぜそうなるのか、それはmaven-scr-pluginのコアタスクではありません。

于 2014-03-09T11:37:52.210 に答える