简体   繁体   English

为 Cucumber Selenium 项目创建可执行 jar 文件

[英]Create executable jar file for Cucumber Selenium project

Problem : I want to create an executable jar of my BDD Cucumber Selenium framework, which I can run using command like "java -jar bddframework-0.0.1-SNAPSHOT.jar".问题:我想为我的 BDD Cucumber Selenium 框架创建一个可执行 jar 框架,我可以使用类似“java -jar bddframework.SNAPSHOT.jar”之类的命令运行它。

What I tried:我尝试了什么:

  1. I tried to directly create a jar file by "mvn clean package".我尝试通过“mvn clean package”直接创建一个 jar 文件。 I did get an jar file but when I run it using java -jar ***, I get below message:我确实得到了一个 jar 文件,但是当我使用 java -jar *** 运行它时,我收到以下消息:

    no main manifest attribute, in bddframework-0.0.1-SNAPSHOT.jar没有主要清单属性,在 bddframework-0.0.1-SNAPSHOT.jar

  2. Then I tried adding a main method as below by adding a new Main.java.然后我尝试通过添加新的 Main.java 来添加如下主要方法。

public static void main(String[] args) throws Throwable {
        String[] arguments = {"--plugin", "html:build/reports/cucumber", "--glue", "com.demo.amazonbdddocker.teststeps", "src/test/resources/feature"};
        cucumber.api.cli.Main.main(arguments);
    }

Still I get the same error: no main manifest attribute我仍然得到同样的错误:没有主要的清单属性

The root cause of that issue is you are just creating a jar file NOT EXECUTABLE JAR.该问题的根本原因是您只是在创建 jar 文件而不是可执行的 JAR。 In order to create the executable jar, you need to do the below configuration in the POM.xml and after that you will be able to create the executable jar file.为了创建可执行文件 jar,您需要在 POM.xml 中进行以下配置,然后您将能够创建可执行文件 jar 文件。

<build>
  <plugins>
    <plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>fully.qualified.MainClass</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
      </configuration>
    </plugin>
  </plugins>
</build>

and then you can run the below maven goals然后您可以运行以下 maven 目标

mvn clean compile assembly:single

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

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