【问题标题】:Create executable JAR in Cucumber/Java project in Intellij/idea在 Intellij/idea 的 Cucumber/Java 项目中创建可执行 JAR
【发布时间】:2014-10-05 09:36:16
【问题描述】:

我需要为我的基于 Java 的 Cucumber 项目创建一个可执行的 JAR。

这是我的文件夹结构:

https://imagizer.imageshack.us/v2/229x373q90/674/EiXWux.png

(main/java/skeleton 中的 Bellyclass 也没有使用)。所有功能步骤都在 resources/skeleton 文件夹中,所有步骤定义都在 test/java/skeleton

未显示的文件有: - gitignore、build.xml、cucumber-java-skeleton.iml、pom.xml 和 README.md

我尝试做一些研究,但很难找出我应该在我的 pom.xml 文件中包含的内容。我目前使用 Intellij 运行我的项目,但我需要将它交给可以在 iOS/Mac 上轻松运行该项目的人。

最好的问候,V。

【问题讨论】:

    标签: java intellij-idea cucumber pom.xml executable-jar


    【解决方案1】:

    我看不到你的结构,但根据我的经验,你可以按照下面的结构来生成 jar。

    假设我们使用的是 maven,我们可以有类似 "src/main/java" 的结构。

    1:- 创建主类并在里面使用下面的代码

    • String[] 参数 = {"--glue", "path/to/glue/code","--glue", "第二个/路径/到/胶水代码", "--tags","@test", 路径,"--plugin","pretty","--plugin","json:/path/to/report"}; cucumber.api.cli.Main.main(参数);

    在 pom.xml 中添加以下插件以创建具有依赖关系的可运行 jar:-

    <plugin>
                               <groupId>org.apache.maven.plugins</groupId>
                               <artifactId>maven-assembly-plugin</artifactId>
                               <executions>
                                   <execution>
                                       <phase>package</phase>
                                       <goals>
                                           <goal>single</goal>
                                       </goals>
                                       <configuration>
                                           <archive>
                                               <manifest>
                                                   <mainClass>
                                                       com.cucumber.CucumberMain
                                                   </mainClass>
                                               </manifest>
                                           </archive>
                                           <descriptorRefs>
                                               <descriptorRef>jar-with-dependencies</descriptorRef>
                                           </descriptorRefs>
                                       </configuration>
                                   </execution>
                               </executions>
                           </plugin>
    

    在此之后,只需使用 mvn clean install 构建您的代码并使用 java -jar "path and name of jar" 运行 jar。它会起作用的。

    注意:- 在 cucumber main 内部,执行任务后,它会调用 system.exit(..),因此在调用它之后你不能在你的代码中做任何事情,直到你使用 shutdownhook。

    【讨论】:

    • 您好,您可以粘贴 CucumberMain 类的示例代码吗?我不明白到底应该把它放在哪里。
    猜你喜欢
    • 2013-06-06
    • 1970-01-01
    • 2019-09-28
    • 2016-09-03
    • 2014-07-29
    • 1970-01-01
    • 2017-05-14
    • 2017-11-14
    • 2014-10-04
    相关资源
    最近更新 更多