Exception in thread "main" java.lang.NoClassDefFoundError: cucumber/api/cli/Main

940 views
Skip to first unread message

Sadakar Pochampalli

unread,
Mar 30, 2020, 7:35:40 AM3/30/20
to Cukes
Hi, 
I'm quite new to automation tools and technologies. I'm trying run cucumber project from maven generated jar file and when run the jar I'm getting below error message. 
If anybody come across the same and have some inputs, that would be of great help. 

Error message: 

C:\Users\sadakarp\.m2\repository\Jaspersoft_Automation\Jaspersoft_Automation\0.0.1-SNAPSHOT>java -jar Jaspersoft_Automation-0.0.1-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: cucumber/api/cli/Main
        at com.sadakar.cucumber.runner.CucumberRunner.main(CucumberRunner.java:41)
Caused by: java.lang.ClassNotFoundException: cucumber.api.cli.Main
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 1 more

BasePage
package com.sadakar.selenium.common;

import org.openqa.selenium.WebDriver;
public class BasePage {
public  static WebDriver driver;
}

CucumberRunner
package com.sadakar.cucumber.runner;

import org.junit.runner.RunWith;
import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import cucumber.api.cli.Main;

@RunWith(Cucumber.class)
@CucumberOptions
(
features="classpath:features",
//tags="@ValidLogin,@InvalidLogin",
tags="@ValidLogin",
glue={"com.sadakar.cucumber.stepdefinitions/","com.sadakar.cucumber.common"},
plugin = { "pretty", "json:target/cucumber-reports/Cucumber.json",
"junit:target/cucumber-reports/Cucumber.xml",
"html:target/cucumber-reports"},
monochrome = true
)
public class CucumberRunner {

public static void main(String args[]) throws Throwable{
try {
String[] arguments = {
"--features","classpath:features",
"--tags","@ValidLogin",
"--glue","com.sadakar.cucumber.stepdefinitions/",
"--glue","com.sadakar.cucumber.common",
"--plugin","pretty", 
"--plugin","json:target/cucumber-reports/Cucumber.json",
"--plugin", "html:target/cucumber-reports"
};
 
    cucumber.api.cli.Main.main(arguments);
}
catch(Exception e) {
System.out.println("Main method exception");
}

}
}

pom.xml

  <modelVersion>4.0.0</modelVersion>
  <groupId>Jaspersoft_Automation</groupId>
  <artifactId>Jaspersoft_Automation</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>Jaspersoft_Automation</name>
  <description>Jaspersoft_Automation</description>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
  
  <!--  cucumber-java -->
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.5</version>
</dependency>
  
  <!--  cucumber-junit -->
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-junit</artifactId>
    <version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-core</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-picocontainer</artifactId>
    <version>1.2.5</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
</dependency>
<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>
<dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>
  </dependencies>
  <build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.sadakar.cucumber.runner.CucumberRunner</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

Shannon Cole

unread,
Mar 30, 2020, 6:04:02 PM3/30/20
to Cukes
Hi Sadakar,

You could try:

    jar tf Jaspersoft_Automation-0.0.1-SNAPSHOT.jar

To verify that the Cucumber main class is indeed in the jar.

Cheers,

Shannon

Sadakar Pochampalli

unread,
Mar 31, 2020, 4:49:33 AM3/31/20
to Cukes
Hi Shannon, 
Thank you for the inputs. I generally looking at MANIFEST.FT file for the main class.
After doing a lot of R&D I could able to run cucumber project from maven generated jar file from command prompt. 

1. build command used in eclipse : clean package shade:shade
2. plugin in pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>com.sadakar.selenium.common.BasePage</mainClass>
</manifest>
</archive>
</configuration>
</plugin>


3. BasePage.java
package com.sadakar.selenium.common;

import org.openqa.selenium.WebDriver;
public class BasePage {
public  static WebDriver driver;

public static void main(String args[]) throws Throwable{
try {
cucumber.api.cli.Main.main(
new String[]{
"classpath:features",
"-t","@ValidLogin",
"-g", "com.sadakar.cucumber.stepdefinitions/", 
"-g","com.sadakar.cucumber.common",
"-p","pretty", 
"-p","json:target/cucumber-reports/Cucumber.json",
"-p", "html:target/cucumber-reports",
}
); 
}
catch(Exception e) {
System.out.println("Main method exception");
}
}
}

4.  C:\Users\sadakarp\eclipse-workspace\SMAPI_UI_POC\target>java -jar SMAPI_UI_POC-0.0.1-SNAPSHOT.jar

Nick Stolwijk

unread,
Apr 6, 2020, 4:11:40 AM4/6/20
to cu...@googlegroups.com
Normally, Maven will not create a runnable jar with all the dependencies. You will need the assembly plugin for that. [1]

But why are you trying to run the jar instead of using Surefire to run your tests?


Hth,

Nick Stolwijk

~~~ Try to leave this world a little better than you found it and, when your turn comes to die, you can die happy in feeling that at any rate you have not wasted your time but have done your best ~~~

Lord Baden-Powell


--
Posting rules: https://cucumber.io/support/posting-rules
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cukes/be37bb15-06ed-46ff-b99a-7e8a5cf39817%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages