简体   繁体   中英

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".

What I tried:

  1. I tried to directly create a jar file by "mvn clean package". I did get an jar file but when I run it using java -jar ***, I get below message:

    no main manifest attribute, in bddframework-0.0.1-SNAPSHOT.jar

  2. Then I tried adding a main method as below by adding a new 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. 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.

<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

mvn clean compile assembly:single

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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