简体   繁体   English

在Intellij / idea的Cucumber / Java项目中创建可执行JAR

[英]Create executable JAR in Cucumber/Java project in Intellij/idea

I need to create an executable JAR for my Javabased Cucumber project. 我需要为基于Java的Cucumber项目创建一个可执行JAR。

This is my folder structure: 这是我的文件夹结构:

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

(The Bellyclass in main/java/skeleton is also not used). (也不使用main / java / skeleton中的Bellyclass)。 All the feature steps are in the resources/skeleton folder and all step definitions are under test/java/skeleton 所有功能步骤都在resources / skeleton文件夹中,所有步骤定义都在test / java / skeleton下

the files that are not displayed are: - gitignore, build.xml, cucumber-java-skeleton.iml, pom.xml and README.md 未显示的文件为:-gitignore,build.xml,cucumber-java-skeleton.iml,pom.xml和README.md

I've tried to do some research, but struggled finding out what I should include in my pom.xml file. 我尝试进行一些研究,但是努力寻找应该包含在pom.xml文件中的内容。 I have currently ran my project using Intellij, but I need to hand it over to someone that can easily run the project on iOS/Mac. 我目前使用Intellij运行我的项目,但是我需要将其交给可以轻松在iOS / Mac上运行该项目的人员。

Best regards, V. 最好的问候,V.

I could not see your structure , but as per my experience you can follow below structure to generate jar. 我看不到您的结构,但是根据我的经验,您可以按照以下结构来生成jar。

Suppose we are using maven we can have "src/main/java" like structure. 假设我们正在使用Maven,我们可以拥有类似“ src / main / java”的结构。

1:- Create main class and inside that use below code 1:-使用以下代码创建主类和内部

  • String[] arguments = {"--glue", "path/to/glue/code","--glue", "Second/Path/to/glue code", "--tags","@test", path,"--plugin","pretty","--plugin","json:/path/to/report"}; String [] arguments = {“ --glue”,“ path / to / glue / code”,“-glue”,“ Second / Path / to / glue代码”,“ --tags”,“ @ test”, path,“-plugin”,“ pretty”,“-plugin”,“ json:/ path / to / report”}; cucumber.api.cli.Main.main(arguments); cumul.api.cli.Main.main(参数);

Add below plugin in pom.xml to create runnable jar with dependency:- 在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>

After this just build your code using mvn clean install and run the jar using java -jar "path and name of jar". 之后,只需使用mvn clean install构建代码,然后使用java -jar“ jar的路径和名称”运行jar。 It would work. 会的。

Note:- Inside cucumber main, after performing task ,it calls system.exit(..), hence you can not do anything in you code after calling it until you use shutdownhook. 注意:-在黄瓜主管道内部,执行任务后,它将调用system.exit(..),因此在调用它之后,除非使用shutdownhook,否则您将无法在代码中进行任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM