【问题标题】:Manifest.mf cannot find org.junitManifest.mf 找不到 org.junit
【发布时间】:2013-04-16 08:57:13
【问题描述】:

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

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

我在 Internet 上看到我必须将 jUnit 添加到 Build-Path。 -> 我已经这样做了。此外,我读到我必须在我的 Manifest.mf 文件中添加 jUnit 作为 require-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:无法解析捆绑myTestBundle 分辨率错误: 捆绑 myTestBundle - 缺少约束:导入包: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 更新站点,现在我没有收到任何错误!

【问题讨论】:

  • 你能发布 pom 文件吗,因为我假设你错过了在 pom 文件中添加 junit 依赖项。
  • 现在我添加了,谢谢你的帮助!!
  • Tycho 应该打印出更好的错误信息:bugs.eclipse.org/bugs/show_bug.cgi?id=405790
  • IsaMunich,欢迎来到 stackoverflow。看来您已经找到了问题的解决方案。在这种情况下,您应该回答自己的问题并接受该答案。这是为了让其他人知道他们不需要提供进一步的答案。

标签: maven junit tycho


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-08
    • 1970-01-01
    • 2013-04-17
    • 1970-01-01
    • 2018-12-12
    • 2015-02-09
    • 2017-03-03
    • 2015-01-29
    相关资源
    最近更新 更多