Maven无法识别jBehave

12

我刚开始学习 jBehave 和 Maven(在 Eclipse 中)。我已经安装了 JBehave Eclipse 1.0.0.20140605-071,并将其添加到我的 Maven 依赖项中 - pom.xml 的相关部分如下所示(在回复后进行编辑):

<dependencies>
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    <scope>test</scope>
  </dependency>
  <dependency>
    <groupId>org.wmaop</groupId>
    <artifactId>wm-jbehave</artifactId>
    <version>1.0.0</version>
    <scope>test</scope>
  </dependency>
</dependencies>
<repositories>
  <repository>
    <id>jitpack.io</id>
    <url>https://jitpack.io</url>
  </repository>
</repositories>

这让我出现了一个错误:

missing artefact org.wmaop:wm-jbehave.jar:1.0.0

如果我尝试构建,会出现错误:

Failure to find org.wmaop:wm-jbehave:jar:1.0.0 in https://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]

"使用Maven创建测试项目" 教程 中提到:"如果项目中存在错误,请打开pom.xml文件检查是否找不到wm-jbehave依赖项。验证您的Designer可以访问互联网以检索jar依赖项",但我不知道这是什么意思——计算机肯定已经连接了互联网——我正在上面打字。

我该如何解决这个错误?


你只需要在Eclipse中学习JBehave吗?或者你需要使用webMethods Integration Suite WM-AOP的测试工具来运行JBehave故事?所有问题都来自于缺少WM-AOP库,也许最好先单独学习JBehave,而不增加WM-AOM框架的复杂性? JBehave不需要WM_AOM,它可以在许多框架上运行,甚至可以不用任何框架,直接从命令行运行。 - krokodilko
我习惯使用Cucumber和Ruby进行BDD。基本上,我想为Java创建一个类似的环境,而JBehave似乎是最有可能的选择(Eclipse是我的首选IDE)。我的问题只是我无法使安装说明正常工作 - 我甚至不确定WM-AOP在哪里适用,除了它在我收到的错误消息中提到。 - digitig
5个回答

6
我甚至不确定WM-AOP的作用,除了在我收到的错误信息中提到它。
看起来你甚至不知道什么是WM-AOP :)
这个 tutorial(来自你的问题)展示了如何与webMethods Designer一起启用和运行JBehave。
换句话说,这是一个独立的产品(集成服务器),它使用另一个独立的项目JBehave
为了运行此教程,您需要首先下载、安装和配置webMethods Designer和Integration Server Flow services。, 然后创建一个使用该服务器和JBehave在该服务器上运行测试的项目。
但是,你不需要这些东西来学习JBehave。JBehave是一个独立的产品,可以在许多环境中运行,甚至在纯Java(JDK)中也可以运行。

只需按照以下步骤进行:
在Eclipse中-点击新建/Maven项目

输入图像描述


2. 在下面的对话框中,单击“下一步”

enter image description here


3. 在下一页中输入 "jbehave-simple-archetype",选择版本 4.1 并点击下一步
注意 - 不要使用最新版本 4.1.1,因为它无法正常工作(有一个错误将在即将发布的版本 4.1.2 中解决,在1-2周内发布) 在此输入图像描述


4. 输入您的项目的组ID和Artifact ID,然后单击完成。 在此输入图像描述


这就是全部 - 您的 JBehave 项目已准备就绪。


src/main/resources/org/example/myJbehave/stories/ 目录下,您将找到一个示例故事 my.story
Scenario: A scenario with some pending steps

Given I am a pending step
And I am still pending step
When a good soul will implement me
Then I shall be happy

src/main/java/org/example/myJbehave/steps/ 中,您会找到 MySteps.java 类。将其修改为以下方式:

import org.jbehave.core.annotations.Alias;
import org.jbehave.core.annotations.Given;
import org.jbehave.core.annotations.Then;
import org.jbehave.core.annotations.When;

public class MySteps {

    @Given("I am a pending step")
    @Alias("I am still pending step")
    public void given_i_am_pending_step() {

        System.out.println("Tihis is implementation of GIVEN");
    }

    @When("a good soul will implement me")
    public void when_a_good_soul_will_implement_me() {
        System.out.println("Tihis is implementation of WHEN");
    }

    @Then("I shall be happy")
    public void then_i_shall_be_happy() {
        System.out.println("Tihis is implementation of THEN");
    }
}

/src/main/java/org/example/myJbehave/目录下,您会找到MyStories.java文件。
该类包含配置和引导代码。
使用鼠标右键单击它,然后选择"Run as / JUnit test",即可执行该故事。 enter image description here

enter image description here


你会在控制台选项卡中看到类似于以下的结果:
Processing system properties {}
Using controls EmbedderControls[batch=false,skip=false,generateViewAfterStories=true,ignoreFailureInStories=true,ignoreFailureInView=true,verboseFailures=false,verboseFiltering=false,storyTimeouts=60,threads=2,failOnStoryTimeout=false]

(BeforeStories)
Running story org/example/myJbehave/stories/my.story
Tihis is implementation of GIVEN
Tihis is implementation of GIVEN
Tihis is implementation of WHEN
Tihis is implementation of THEN

(org/example/myJbehave/stories/my.story)
Scenario: A scenario with some pending steps
Given I am a pending step
And I am still pending step
When a good soul will implement me
Then I shall be happy



(AfterStories)
Generating reports view to 'C:\Users\irko\eclipse-workspace1\myJbehave\target\jbehave' using formats '[stats, console, txt, html, xml]' and view properties '{navigator=ftl/jbehave-navigator.ftl, views=ftl/jbehave-views.ftl, reports=ftl/jbehave-reports.ftl, nonDecorated=ftl/jbehave-report-non-decorated.ftl, decorated=ftl/jbehave-report-decorated.ftl, maps=ftl/jbehave-maps.ftl}'
Reports view generated with 2 stories (of which 0 pending) containing 1 scenarios (of which 0 pending)

注意:按照这些步骤安装JBehave Eclipse插件,其中包含有用的*.story编辑器。

不行,在第三步就失败了。那个页面没有显示任何原型,当我输入jbehave-simple-archetype时,Eclipse会崩溃并出现内存错误——Java堆空间。我已经尝试使用-vmargs -Xmx1000M启动Eclipse,但仍然出现相同的错误。 - digitig
根据 https://howtodoinjava.com/tools/eclipse/how-to-import-maven-remote-archetype-catalogs-in-eclipse/ 上的说明获取原型的本地副本后,错误变为“在 Eclipse 中找不到处理 jbehave-maven-plugin:4.1:unpack-view-resources 的市场条目。请参阅帮助以获取更多信息。”我找不到任何相关的帮助。 - digitig

4
据我所见,它并不在Maven中央仓库上,所以不足为奇,但它可以在GitHub上找到,因此让我们使用JitPack从那里获取它。
将此添加到您的POM中。
<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>

仅仅添加并更新项目还不够,构建也不行。我需要做些什么来强制获取(fetch)吗? - digitig
看来你得自己构建它。https://github.com/wmaop/wm-jbehave/releases。只需记得包括父pom。 - Antoniossss
我该如何包含父POM?这是我使用Maven的第一天... - digitig

3
请尝试使用此代码库替代:https://repo.azure.jenkins.io/public
或者在本地构建该项目:
git clone https://github.com/wmaop/wm-jbehave.git --branch  wm-jbehave-1.0.0
cd wm-jbehave
mvn clean install

添加那个存储库没有任何影响。按照本地构建说明进行操作后,出现了我熟悉的错误: [ERROR] 项目 org.wmaop:wm-jbehave:1.0.0 (C:\Users\digit\Desktop\jbehave\wm-jbehave\pom.xml) 有 1 个错误 [ERROR] 对于 org.wmaop:wm-jbehave:1.0.0 的非可解析父 POM:在 https://repo.maven.apache.org/maven2 中找不到 org.wmaop:wm-parent:pom:1.0.5 已被缓存在本地存储库中,在 central 更新间隔已过期或强制更新之前不会重新尝试解决,并且 'parent.relativePath' 指向了错误的本地 POM @ 第 8 行,第 10 列。 - digitig
你想继续使用 VM JBehave 1.0.0 版本,还是愿意尝试另一个版本?如果是的话,可以尝试 1.1.0 版本,它更容易找到。 - sab

1
根据所发布的错误信息:
“在 https://repo.maven.apache.org/maven2 中未能找到 org.wmaop:wm-jbehave:jar:1.0.0 的缓存已保存在本地仓库中,直到中央更新时间间隔过去或强制更新后将不会再次尝试解决 -> [Help 1]”
似乎项目需要强制进行maven更新以解决缺失的构件。只需右键单击您的项目 -> Maven -> Update Project。确保选中“Force Update of Snapshots/Releases”。

0

以下的Maven依赖和仓库条目可用于编译基于问题中的教程链接的示例Maven项目。

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.wmaop</groupId>
        <artifactId>wm-jbehave</artifactId>
        <version>1.1.1</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>com.entrust</groupId>
                <artifactId>toolkit</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.softwareag.webmethods</groupId>
                <artifactId>wm-isserver</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.softwareag.webmethods</groupId>
                <artifactId>wm-isclient</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>bintray.io</id>
        <url>https://dl.bintray.com/wmaop/maven</url>
    </repository>
</repositories>

请注意,本教程还需要额外的设置才能运行HelloWorld故事。
使用简单的jbehave maven原型,按照@krokodilko提供的答案可能更容易。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接