首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用pax-maven-plugin构建时,将自己的包源添加到pax- to中。

使用pax-maven-plugin构建时,将自己的包源添加到pax- to中。
EN

Stack Overflow用户
提问于 2012-04-12 08:49:27
回答 2查看 3.8K关注 0票数 5

我正在尝试用pax-maven-构建构建我的OSGI,同时用pax考试测试它。它提供了一些包,我无法用下面的pax- test配置进行测试:

代码语言:javascript
复制
@RunWith(JUnit4TestRunner.class)
@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
public class OSGILoaderTest {

    @Inject
    protected BundleContext bundleContext;

    @Configuration
    public Option[] config() throws MalformedURLException {


        String projectRoot = // a path to my project

        return options(
                junitBundles(),
                equinox(),
                bundle(projectRoot + "libs/org.eclipse.core.variables_3.2.500.v20110511.jar"),
                bundle(projectRoot + "libs/org.eclipse.core.contenttype_3.4.100.v20110423-0524.jar"),
                bundle(projectRoot + "libs/org.eclipse.core.expressions_3.4.300.v20110228.jar"),
                // etc...
        );
    }

    @Test
    public void getBundleContext() throws RodinDBException {
        IRodinDB rodinDB = RodinCore.getRodinDB();
        assertNotNull(rodinDB);
    }
}

在这里,我可以从一个附带条件的jar中访问IRodinDB实例。

现在我有了自己的包代码,它将使用提供的所有jar。但是我甚至不能测试我自己的代码,例如:

代码语言:javascript
复制
@Test
public void checkAccessToRodinDbTest() {
    VTGService service = null;
    assertTrue(true);
}

在编译时给出一个错误

错误未能执行目标org.ops4j:maven-pax-plugin:1.5:testCompile (默认-testCompile):编译失败 错误找不到符号 错误符号:类VTGService

测试编译似乎不能看到'src/main/java',这与maven编译器插件的默认行为相反。但是在我的例子中,您可以看到maven并不使用编译器插件,而是使用maven-pax-plugin。

问题是:我如何用pax考试测试我自己的包?

update1

这似乎是最近版本的maven- Pax -plugin的一个问题,因为ops4j pax插件中可用的基本示例 (在POM中使用Pax插件的部分)似乎也遇到了同样的问题。

update2

按照Dmytro的要求,这是my的pom.xml:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

    <parent>
        <relativePath>../poms/compiled/</relativePath>
        <groupId>fr.xlim.ssd.vtg.build</groupId>
        <artifactId>compiled-bundle-settings</artifactId>
        <version>0.1-SNAPSHOT</version>
    </parent>

    <properties>
        <bundle.symbolicName>fr.xlim.ssd.vtg.bundle</bundle.symbolicName>
        <bundle.namespace>fr.xlim.ssd.vtg.bundle</bundle.namespace>
    </properties>

    <modelVersion>4.0.0</modelVersion>
    <groupId>fr.xlim.ssd.vtg</groupId>
    <artifactId>fr.xlim.ssd.vtg.bundle</artifactId>
    <version>0.1-SNAPSHOT</version>

    <name>${bundle.symbolicName}</name>

    <packaging>bundle</packaging>

    <dependencies>

        <dependency>
            <type>pom</type>
            <groupId>${project.parent.groupId}</groupId>
            <artifactId>provision</artifactId>
            <optional>true</optional>
        </dependency>

        <!-- not needed as equinox bundle are available in provision --> 
        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>osgi_R4_core</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.osgi</groupId>
            <artifactId>osgi_R4_compendium</artifactId>
            <optional>true</optional>
        </dependency-->

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.9</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.ops4j.pax.exam</groupId>
            <artifactId>pax-exam</artifactId>
            <version>2.3.0</version>
            <scope>test</scope>
        </dependency>

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

        <dependency>
            <groupId>org.ops4j.pax.exam</groupId>
            <artifactId>pax-exam-inject</artifactId>
            <version>2.3.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.ops4j.pax.url</groupId>
            <artifactId>pax-url-mvn</artifactId>
            <version>1.3.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.ops4j.pax.exam</groupId>
            <artifactId>pax-exam-container-native</artifactId>
            <version>2.3.0</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
            <scope>test</scope>
        </dependency>

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

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.0.0</version>
        </dependency>

        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>1.0.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

我不确定这是最优雅的解决方案,但我创建了一个新的maven项目,当我可以导入我自己的包时,就像在我问题的源代码中一样。

是否有一种优雅的方法可以直接将我自己的java源代码作为新包添加到同一个Maven项目中进行测试?这可能是不可能的(因为捆绑汇编操作是在之后编译和测试完成的).

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-04-12 12:09:26

我使用下面的设置来提供测试中的包。在配置测试时,我使用reference-protocol提供包(这是Equinox和Felix的一个非标准特性,参见这里):

代码语言:javascript
复制
@Configuration
public Option[] config() {

    return options(         
        bundle("reference:file:target/classes"),
        junitBundles(),
        felix()
        );
}

当您指定knopplerfish()作为环境时,测试用例也会运行。我猜这是因为URL是由Pax考试解决的,而不是由OSGi运行时解析的。我使用maven-bundle插件构建包。要使此工作如愿以偿,您必须添加以下配置:

代码语言:javascript
复制
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.7</version>
            <extensions>true</extensions>
            <executions>
                <!-- This execution makes sure that the manifest is available 
                    when the tests are executed -->
                <execution>
                    <goals>
                        <goal>manifest</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

否则,在运行测试时,清单将不可用,因为默认情况下,清单是在package-phase期间生成的。

我希望我没有忘记任何事情-请告诉我,如果它对你有用!

票数 5
EN

Stack Overflow用户

发布于 2012-04-12 09:00:03

检查PaxExam文档如何使用PaxExam配置Maven POM。

样本这里

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10120277

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档