2012-12-14 5 views
1

다음 상황 : maven 및 maven-bundle-plugin을 사용하여 OSGi 응용 프로그램을 개발 중입니다. 나는 Unit Tests를 운영하여 Pax-Exam을 발견하고 적절한 결과를 얻었습니다.maven-bundle plugin 및 pax-exam : MANIFEST.MF가 존재하지 않습니다.

import static org.ops4j.pax.exam.CoreOptions.*; 
import org.junit.Test; 
import org.junit.runner.RunWith; 
import org.ops4j.pax.exam.Option; 
import org.ops4j.pax.exam.junit.Configuration; 
import org.ops4j.pax.exam.junit.ExamReactorStrategy; 
import org.ops4j.pax.exam.junit.JUnit4TestRunner; 
import org.ops4j.pax.exam.spi.reactors.AllConfinedStagedReactorFactory; 

import org.osgi.framework.Bundle; 
import org.osgi.framework.BundleContext; 
import javax.inject.Inject; 

@RunWith(JUnit4TestRunner.class) 
@ExamReactorStrategy(AllConfinedStagedReactorFactory.class) 
public class SampleTest { 

@Inject 
BundleContext bu = null; 

@Configuration 
public Option[] config() { 

    return options(junitBundles()); 
} 

@Test 
public void getHelloService() { 
    for (Bundle b : bu.getBundles()) { 
     System.out.println("Bundle " + b.getBundleId() + " : " 
       + b.getSymbolicName()); 
    } 
} 

}

: 여기

내가 간단한 테스트 케이스를 포함하는 모듈 작업 공간-osgiframework-테스트를 ​​만들었습니다

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
<modelVersion>4.0.0</modelVersion> 
<groupId>de.hswt.oms</groupId> 
<artifactId>workspace-parent</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<packaging>pom</packaging> 
<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 

<repositories> 
    <repository> 
     <id>com.springsource.repository.bundles.release</id> 
     <name>SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name> 
     <url>http://repository.springsource.com/maven/bundles/release</url> 
    </repository> 

    <repository> 
     <id>com.springsource.repository.bundles.external</id> 
     <name>SpringSource Enterprise Bundle Repository - External Bundle Releases</name> 
     <url>http://repository.springsource.com/maven/bundles/external</url> 
    </repository> 
</repositories> 
<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-jar-plugin</artifactId> 
      <version>2.4</version> 
      <configuration> 
       <archive> 
        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile> 
        <manifestEntries> 
         <Built-By>Tobias Placht</Built-By> 
         <Bundle-ActivationPolicy>lazy</Bundle-ActivationPolicy> 
        </manifestEntries> 
       </archive> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>maven-bundle-plugin</artifactId> 
      <version>2.3.7</version> 
      <configuration> 
       <instructions> 
        <Export-Package>{local-packages};version="${project.version}"</Export-Package> 
        <Import-Package>*</Import-Package> 
        <Private-Package>{local-packages}</Private-Package> 
        <Service-Component>*</Service-Component> 
       </instructions> 
      </configuration> 
      <executions> 
       <execution> 
        <id>bundle-manifest</id> 
        <phase>process-classes</phase> 
        <goals> 
         <goal>manifest</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.5.1</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.12.4</version> 
      <dependencies> 
       <dependency> 
        <groupId>org.apache.maven.surefire</groupId> 
        <artifactId>surefire-junit47</artifactId> 
        <version>2.12.4</version> 
       </dependency> 
      </dependencies> 
     </plugin> 
     <plugin> 
      <groupId>org.ops4j</groupId> 
      <artifactId>maven-pax-plugin</artifactId> 
      <version>1.5</version> 
      <configuration> 
       <provision> 
        <param>--profiles=ds</param> 
        <param>--platform=equinox</param> 
        <param>mvn:de.hswt.oms/workspace-datastructure-core/[email protected]</param> 
        <param>mvn:de.hswt.oms/workspace-command-core/[email protected]</param> 
        <param>mvn:de.hswt.oms/workspace-facade/[email protected]</param> 
       </provision> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
<dependencies> 
    <dependency> 
     <groupId>org.apache.felix</groupId> 
     <artifactId>org.osgi.core</artifactId> 
     <version>1.4.0</version> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
     <version>1.6.6</version> 
    </dependency> 
    <dependency> 
     <groupId>ch.qos.logback</groupId> 
     <artifactId>logback-core</artifactId> 
     <version>1.0.7</version> 
    </dependency> 
    <dependency> 
     <groupId>ch.qos.logback</groupId> 
     <artifactId>logback-classic</artifactId> 
     <version>1.0.7</version> 
    </dependency> 
    <dependency> 
     <groupId>org.junit</groupId> 
     <artifactId>com.springsource.org.junit</artifactId> 
     <version>4.11.0</version> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 
<modules> 
    <module>workspace-datastructure-core</module> 
    <module>workspace-command-core</module> 
    <module>workspace-log-config</module> 
    <module>workspace-wsr-create</module> 
    <module>workspace-datastructure-local</module> 
    <module>workspace-localfile-create</module> 
    <module>workspace-localfolder-create</module> 
    <module>workspace-facade</module> 
    <module>workspace-osgiframework-tests</module> 
</modules> 

내 부모의 pom.xml이다

및 해당 pom.xml

<project 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" 
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
<modelVersion>4.0.0</modelVersion> 
<artifactId>workspace-osgiframework-tests</artifactId> 

<properties> 
    <exam.version>2.5.0</exam.version> 
    <url.version>1.4.0</url.version> 
</properties> 

<parent> 
    <groupId>de.hswt.oms</groupId> 
    <artifactId>workspace-parent</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <relativePath>..</relativePath> 
</parent> 
<build> 
    <plugins> 
     <!-- skip plugin execution explicitly --> 
     <plugin> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>maven-bundle-plugin</artifactId> 
      <extensions>true</extensions> 
      <configuration> 
       <skip>true</skip> 
      </configuration> 
      <executions> 
       <execution> 
        <id>bundle-manifest</id> 
        <phase>none</phase> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.5.1</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 
<dependencies> 

    <dependency> 
     <groupId>org.ops4j.pax.exam</groupId> 
     <artifactId>pax-exam-container-forked</artifactId> 
     <version>${exam.version}</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.ops4j.pax.exam</groupId> 
     <artifactId>pax-exam-junit4</artifactId> 
     <version>${exam.version}</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.ops4j.pax.exam</groupId> 
     <artifactId>pax-exam-link-mvn</artifactId> 
     <version>${exam.version}</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.ops4j.pax.url</groupId> 
     <artifactId>pax-url-aether</artifactId> 
     <version>${url.version}</version> 
     <scope>test</scope> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.felix</groupId> 
     <artifactId>org.apache.felix.framework</artifactId> 
     <version>4.0.2</version> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

나는 내가 MVN 테스트를 실행, 모든 것이 잘 작동하지만 내가 MVN 실행하면 내가 다음과 같은 오류 얻을 설치 : 그것을 제거하는 방법

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 8.546s 
[INFO] Finished at: Fri Dec 14 15:37:50 CET 2012 
[INFO] Final Memory: 27M/233M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-jar-plugin:2.4:jar   (default-jar) on project workspace-osgiframework-tests: Error assembling JAR: Manifest file: /home/knacht/development/repositorys/git/oms/workspace-parent/workspace-osgiframework-tests/target/classes/META-INF/MANIFEST.MF does not exist. -> [Help 1] 

어떤 생각을?

또한 첫 번째 메이븐 프로젝트이므로 조언이 있으면 알려주세요.

+0

주제 조금 : 가능한 경우 아파치 펠릭스 의존성을 없애고 osgi 코어 또는 개론 패키지에 따라 종속성을 바꿔야합니다. 이렇게하면 실수로 비표준 기능을 사용하지 않고 나중에 추분 기나 다른 컨테이너로 전환 할 수 있습니다. – benjamin

+0

힌트를 가져 주셔서 감사합니다. – hueck

답변

3

Maven 및 Pax 시험을 처음 사용하는 경우 가능한 한 기본값을 그대로 사용하는 것이 좋습니다.

maven-jar-plugin과 maven-bundle-plugin을 병렬로 사용하면 충돌이 발생할 수 있습니다. 번들 프로젝트의 Maven 패키지를 "번들"로 변경하고 maven-bundle-plugin이 매니페스트를 생성하도록하십시오. 일반적으로 maven-jar-plugin을 직접 사용할 필요는 없습니다.

maven-pax-plugin은 Pax Exam 2.x에서 더 이상 지원되지 않습니다. 대신 @Configuration 메소드에서 bundle() 옵션을 사용해야합니다.

최신 예제는 https://github.com/ops4j/org.ops4j.pax.exam2/tree/master/itest/src/it/regression-multi의 Pax Exam 자체 통합 테스트를 참조하십시오.

+0

월요일에 시도해 보겠습니다. 나는 pax 시험과 함께하지 않고 OSGi Container에 내 번들을 제공하기 위해 maven-pax-plugin을 사용하고 있습니다. – hueck

+0

패키지를 병에서 번들로 바꾸는 것이 내 문제를 해결했습니다. 고맙습니다 – hueck

관련 문제