Home > Blockchain >  ClassNotFoundException in cucumber framework
ClassNotFoundException in cucumber framework

Time:10-21

I am using cucumber framework for mobile app testing. In pom.xml I have given this below plugin to run TestClass.java - which has code for uploading the latest apk version of the app. Main method is present inside this TestClass. I need this to run before the actual test execution. So have used exec plugin.Im getting this error If I am running with pom.xml --> mvn clean test. ClassNotFoundExpection is always thrown with pom.xml but the individual class runs perfectly.

    pom.xml:
                           <plugin>
                            <groupId>org.codehaus.mojo</groupId>
                            <artifactId>exec-maven-plugin</artifactId>
                            <version>3.0.0</version>
                               <executions>
                            <execution>
                                    <id>installAPK</id>
                                    <phase>generate-test-sources</phase>
                                    <goals>
                                    <goal>java</goal>
                                    </goals>
                                </execution>
                            </executions>
                            <configuration>
                                <includePluginDependencies>true</includePluginDependencies>
                                <mainClass>org.com.package1.TestClass</mainClass>
                            </configuration>
                        </plugin>
Console error:
            java.lang.ClassNotFoundException: org.com.package1.TestClass
                at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
                at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
                at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:246)
                at java.lang.Thread.run(Thread.java:748)
I also tried changing the phase after test-compile. Still i am getting the same error. Someone pls help.

CodePudding user response:

According to the exec-maven-plugin documentation, the default dependency scope for the execution is runtime. Please change it to test with the following configuration if the TestClass is part of the test sources.

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>3.0.0</version>
  <executions>
    ...
  </executions>
  <configuration>
    ...
    <classpathScope>test</classpathScope>
  </configuration>
</plugin>
  • Related