无法在spring引导jar中运行cucumber命令-未找到后端请确保在类路径上有后端模块

vdgimpew  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(365)

我试图通过cucumber.api.cli.main.main运行cucumber,但它给出了以下错误(请注意,在ide中它可以正常工作)

  1. Exception in thread "main" java.lang.reflect.InvocationTargetException
  2. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  3. at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  4. at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  5. at java.lang.reflect.Method.invoke(Unknown Source)
  6. at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
  7. at org.springframework.boot.loader.Launcher.launch(Launcher.java:109)
  8. at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
  9. at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88)
  10. Caused by: cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.
  11. at cucumber.runtime.Runtime.<init>(Runtime.java:81)
  12. at cucumber.runtime.Runtime.<init>(Runtime.java:70)
  13. at cucumber.runtime.Runtime.<init>(Runtime.java:66)
  14. at cucumber.api.cli.Main.run(Main.java:35)
  15. at cucumber.api.cli.Main.main(Main.java:18)
  16. at br.com.xxx.service.xxx.test.TesteCucumber.main(TesteCucumber.java:17)
  17. ... 8 more

我的主课

  1. @Configuration
  2. @EnableAutoConfiguration
  3. @ComponentScan(basePackages = { "br.com.xxx" })
  4. @SpringBootApplication
  5. public class TesteCucumber {
  6. public static void main(String[] args) throws Throwable {
  7. String[] arguments = {"..\\src\\test\\resources\\","-g", "br.com.xxx.service.xxx.test.cucumber.steps"};
  8. cucumber.api.cli.Main.main(arguments);
  9. }
  10. }

我的pom配置

  1. <properties><cucumber.version>1.2.5</cucumber.version></properties>
  2. <dependency>
  3. <groupId>info.cukes</groupId>
  4. <artifactId>cucumber-java</artifactId>
  5. <version>${cucumber.version}</version>
  6. </dependency>
  7. <dependency>
  8. <groupId>info.cukes</groupId>
  9. <artifactId>cucumber-junit</artifactId>
  10. <version>${cucumber.version}</version>
  11. </dependency>
  12. <dependency>
  13. <groupId>info.cukes</groupId>
  14. <artifactId>gherkin</artifactId>
  15. <version>2.12.2</version>
  16. </dependency>
  17. <dependency>
  18. <groupId>info.cukes</groupId>
  19. <artifactId>cucumber-spring</artifactId>
  20. <version>${cucumber.version}</version>
  21. </dependency>

spring引导jar中的所有依赖项都正常

我已经搜索了一些类似的问题,但没有找到答案
你能帮我解决这个错误吗?提前谢谢。

xa9qqrwz

xa9qqrwz1#

我这样解决了这个问题
在pom.xml中,我将maven配置为添加main类cucumber.api.cli.main

  1. <build>
  2. <finalName>${project.artifactId}</finalName>
  3. <plugins>
  4. <plugin>
  5. <groupId>org.apache.maven.plugins</groupId>
  6. <artifactId>maven-jar-plugin</artifactId>
  7. <configuration>
  8. <archive>
  9. <manifest>
  10. <addClasspath>true</addClasspath>
  11. <classpathPrefix>lib/</classpathPrefix>
  12. <mainClass>cucumber.api.cli.Main</mainClass>
  13. </manifest>
  14. </archive>
  15. </configuration>
  16. </plugin>
  17. </plugins>

我在课堂上取消了考试
我运行mvn包
我将所有jar依赖项复制到文件夹/lib/
我运行下面的命令行:

  1. java -jar myjar.jar --glue br.com.xxx.service.hub.test.cucumber.steps "C:\...\src\test\resources\file.feature"
展开查看全部

相关问题