2012-12-14 30 views
1

以下情況:我正在使用maven和maven-bundle-plugin開發OSGi應用程序。我想運行單元測試並發現Pax-Exam,我發現它適合退出。maven-bundle插件和pax-exam:MANIFEST.MF不存在

這是我父母的pom.xml

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

我已經創建的模塊工作空間osgiframework檢驗它包含一個簡單的測試用例:

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

}

和相應的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] 

不知道如何擺脫它?

另外這是我的第一個maven項目,所以如果你有任何意見,請告訴我。

+0

有點偏離主題:如果可能的話,你應該擺脫apache felix依賴關係,並將其替換爲osgi內核或簡編包的相關依賴關係。這可以確保您不會意外地使用非標準功能,並可以在稍後切換到Equinox或任何其他容器。 – benjamin

+0

謝謝你的提示。 – hueck

回答

3

當您剛接觸Maven和Pax考試時,我建議您儘可能地使用默認設置。

並行使用maven-jar-plugin和maven-bundle-plugin可能會導致你所看到的衝突。將捆綁項目的Maven包裝更改爲「捆綁」並讓maven-bundle-plugin生成清單。通常不需要直接使用maven-jar-plugin。

Pax Exam 2.x不再支持maven-pax-plugin。相反,您應該在@Configuration方法中使用bundle()選項。

有關最新的示例,請參閱Pax Exam自己的集成測試,網址爲https://github.com/ops4j/org.ops4j.pax.exam2/tree/master/itest/src/it/regression-multi

+0

星期一我會試一試。我使用maven-pax-plugin將我的Bundle配置到OSGi容器中,而不是與pax考試一起使用。 – hueck

+0

將包裝從罐子更換爲包裝解決了我的問題。謝謝 – hueck