Manifest.mf找不到org.junit

时间:2013-04-16 08:57:13

标签: maven junit tycho

我正在尝试使用Tycho运行Eclipse RCP应用程序的jUnit测试。

为此,我创建了一个简单的jUnit测试,当我点击Run as>基于JUnit测试。但是当我想用mvn测试运行它时,它找不到jUnit。

我在互联网上读到我必须将jUnit添加到Build-Path。 - >我已经这样做了。此外,我读到我必须在我的Manifest.mf文件中添加jUnit作为require-bundle。但是有问题!!我收到错误:Bundle'org.junit'可以解决。

我的MANIFEST.MF文件如下所示:

    Manifest-Version: 1.0
    Bundle-ManifestVersion: 2
    Bundle-Name: Tests
    Bundle-SymbolicName: myPackageName
    Bundle-Version: 1.0.0.qualifier
    Bundle-Vendor: myCompany
    Fragment-Host: thePackageWhereTestesPluginIs
    Bundle-RequiredExecutionEnvironment: JavaSE-1.6
    Require-Bundle: org.junit

我的错误在哪里?当我拿org.junit4它也无法解决...

谢谢!

更新:

现在我使用而不是require-bundle:

    Import-package: org.junit4

(或org.junit,它的'行为是相同的),它可以在manifest.mf文件中解析。但是当我运行它时,我收到以下错误: [错误] - > [帮助1] org.apache.maven.InternalErrorException:内部错误:java.lang.RuntimeException:org.osgi.framework.BundleException:Bundle myTestBundle无法解析 分辨率错误:    捆绑myTestBundle - 缺少约束:Import-Package:org.junit4;版本= “0.0.0”

我该如何解决这个问题?

谢谢!

我的测试包的pom文件:

<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
        <artifactId>myProject.tycho.master</artifactId>
        <groupId>myProject</groupId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../myProject.tycho.master/pom.xml</relativePath>
    </parent>
    <groupId>myProject</groupId>
    <artifactId>myProject.myTestBundle</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>eclipse-test-plugin</packaging>

<dependencies>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.8.1</version>
</dependency>
</dependencies>
</project>

父母pom:

    <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>
<groupId>myProject</groupId>
<artifactId>myProject.tycho.master</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>

<properties>
    <tycho.version>0.17.0</tycho.version>
</properties>

<modules>
    <module>../myProject.myTestBundle</module>

</modules>



<repositories>
    <!-- configure p2 repository to resolve against -->
    <repository>
        <id>Repository1</id>
        <layout>p2</layout>
        <url>url-to-a-p2-site-on-my-server</url>
    </repository>
</repositories>

<build>
    <plugins>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-maven-plugin</artifactId>
            <version>${tycho.version}</version>
            <extensions>true</extensions>
        </plugin>
        <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>target-platform-configuration</artifactId>
            <version>${tycho.version}</version>
            <configuration>
                <resolver>p2</resolver>
                <pomDependencies>consider</pomDependencies>
                <target>
                    <artifact>
                        <groupId>myGroupId</groupId>
                        <artifactId>myGroupId.target</artifactId>
                        <classifier>targetPlatform</classifier>
                    </artifact>
                </target>
                <environments>
                    <environment>
                        <os>macosx</os>
                        <ws>cocoa</ws>
                        <arch>x86_64</arch>
                    </environment>
                    <environment>
                        <os>linux</os>
                        <ws>gtk</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>linux</os>
                        <ws>gtk</ws>
                        <arch>x86_64</arch>
                    </environment>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86</arch>
                    </environment>
                    <environment>
                        <os>win32</os>
                        <ws>win32</ws>
                        <arch>x86_64</arch>
                    </environment>
                </environments>
                <ignoreTychoRepositories>false</ignoreTychoRepositories>
            </configuration>
        </plugin>
    </plugins>
</build>
    </project>

更新: 我想我解决了这个问题! 我将jUnit添加到我的p2更新站点,现在我没有收到任何错误!

1 个答案:

答案 0 :(得分:1)

我通过将jUnit添加为p2更新站点来解决我的问题,并在Manifest.mf中将其用作:

Require-Bundle: org.junit; bundle-version = "4.11.0"