2013-04-17 23 views
5

Tôi đã gặp sự cố khi tải plugin SCR của mình hoạt động. Tôi đã tìm kiếm nhiều như tôi có thể chỉ tìm thấy những ví dụ không giống với cấu trúc mà tôi được yêu cầu sử dụng. Đoạn mã của POM dưới đây. Đây là khá nhiều mặc định được tạo ra bởi nguyên mẫu dự án CQ. Tất cả phụ thuộc đều ở đó, nên có lẽ không phải vậy. Đây là kết quả của bản dựng:Maven SCR Plugin - Không tạo thư mục OSGI-INF

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] ------------------------------------------------------------------------ 

Phần chính của đầu ra là [INFO] --- maven-scr-plugin:1.7.4:scr (generate-scr-descriptor) @ project-bundle ---. Dường như nó không tạo ra bất cứ điều gì mặc dù các chú thích tồn tại trên lớp.

Chánh POM Snippet:

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

Child POM Snippet:

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

Mã được xây dựng:

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

Bất kỳ trợ giúp nào được đánh giá cao.

Trả lời

7

Tôi đoán bạn đang sử dụng <packaging>bundle</packaging>, nếu vì vậy tôi đã làm việc này bằng cách nâng cấp maven-scr-plugin để 1.9.0, với org.apache.felix.scr.annotations @ 1.7.0

Tôi đặt một tarball của một phiên bản làm việc tại đây: https://dl.dropboxusercontent.com/u/2465717/com.stackoverflow.osgi.scr.tgz

Lưu ý: bạn có thể kích hoạt ánh xạ vòng đời Eclipse m2e - nó hoạt động tốt (Juno SR2), tạo ra lỗi thành phần SCR trong bảng điều khiển Vấn đề thông thường. Thay đổi action <ignore/> tới:

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

Cũng trong khi spec chỉ ra thời gian chạy SCR sẽ tìm kiếm de quá tải/kích hoạt các phương pháp - như sở thích cá nhân tôi sẽ sử dụng @Activate, @Deactive và @Modified về các phương pháp tương ứng để thực hiện ý định rõ ràng (trong mã và XML được tạo). Nhưng mỗi sở hữu của họ.

+0

Sử dụng org.apache.felix.scr.annotations mới nhất đã sửa nó trong trường hợp của tôi. –

1

tôi đề nghị bạn nên

  • nâng cấp lên phiên bản mới nhất của maven-scr-plugin
  • tạo debug với -X, ví dụ mvn -X compile
0

Nâng cấp lên 1.9.0 làm việc cho tôi. Có phải chúng ta nói plugin v1.7.4 không tạo ra các bộ mô tả. Tại sao nó sẽ như vậy, không phải là nhiệm vụ cốt lõi của maven-scr-plugin.

Các vấn đề liên quan