Here are the steps performed:
Step 1:
Based on this, I built a standalone jar with all dependencies included using maven-shade-plugin
.
pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<testSourceDirectory>${basedir}/src/main/java/</testSourceDirectory>
<testClassesDirectory>${project.build.directory}/classes/</testClassesDirectory>
<reportsDirectory>${project.build.directory}/test-output/${timestamp}</reportsDirectory>
</configuration>
</plugin>
<!-- https://maven.apache.org/plugins/maven-shade-plugin/examples/executable-jar.html -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<!-- https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html -->
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>standalone</shadedClassifierName>
<transformers>
<!-- https://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html -->
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>runners.RunCukesTest</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Added the main()
method to the runner class and passed cmdline args based on this, this, and this.
RunCukesTest.java
package runners;
import cucumber.api.CucumberOptions;
import cucumber.api.SnippetType;
import cucumber.api.cli.Main;
import cucumber.api.testng.AbstractTestNGCucumberTests;
@CucumberOptions(features = { "src/main/resources/features" }, glue = { "steps" }, tags = { "not @ignore" }, plugin = {
"pretty" }, monochrome = true)
public class RunCukesTest extends AbstractTestNGCucumberTests {
public static void main(String[] args) {
System.out.println("Begin running tests...");
Main.main(new String[]{ "-g", "steps", "-t", "not @ignore", "-p", "pretty", "-m", "src/main/resources/features" });
}
}
Step 2: Tried to run executable JAR.
λ java -jar project-xyz-1.0.0-standalone.jar
Begin running tests...
Exception in thread "main" java.lang.IllegalArgumentException: Not a file or directory: \path\to\jar\src\main\resources\features
at cucumber.runtime.io.FileResourceIterator$FileIterator.<init>(FileResourceIterator.java:63)
at cucumber.runtime.io.FileResourceIterator.<init>(FileResourceIterator.java:28)
at cucumber.runtime.io.FileResourceIterator.createFileResourceIterator(FileResourceIterator.java:14)
at cucumber.runtime.io.FileResourceIterable.iterator(FileResourceIterable.java:19)
at cucumber.runtime.model.FeatureLoader.loadFromFeaturePath(FeatureLoader.java:112)
at cucumber.runtime.model.FeatureLoader.load(FeatureLoader.java:48)
at cucumber.runtime.model.FeatureLoader.load(FeatureLoader.java:30)
at cucumber.runtime.FeaturePathFeatureSupplier.get(FeaturePathFeatureSupplier.java:22)
at cucumber.runtime.Runtime.run(Runtime.java:68)
at cucumber.api.cli.Main.run(Main.java:26)
at cucumber.api.cli.Main.main(Main.java:8)
at runners.RunCukesTest.main(RunCukesTest.java:17)
It reads the main()
method in the runner class but throws
Exception in thread "main" java.lang.IllegalArgumentException: Not a file or directory: \path\to\jar\src\main\resources\features
UPDATE
It seems it is not reading the features
directory inside the JAR.
Main.main(new String[]{ "-g", "steps", "-t", "not @ignore", "-p", "pretty", "-m", "src/main/resources/features" });
How do I point to the features
directory inside the JAR via the cmdline args?