Search code examples
javaseleniumjunitcucumberbdd

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


Solution

  • 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