如何在命令提示符下解决异常“java.lang.IllegalArgumentException:name”而运行spring引导jar但在eclipse中运行很好

How to solve exception " java.lang.IllegalArgumentException: name" while running spring boot jar in command prompt but fine while running in eclipse

我有简单的功能控制器 class,它通过 Rest 调用公开黄瓜测试用例。这是控制器 class

    @RestController
@RequestMapping("/featureTest")
public class FeatureController {

    @RequestMapping(value="/MQEndtoEnd",produces = MediaType.TEXT_HTML_VALUE)
    public String executeFeature(@RequestParam(name = "FeatureFileName") String featureFileName) 
      throws Throwable  {
        String path="D:\citrus\Report_Directory\citrus-test-results.html";         
         String content="";
    
              String[] cucumberOptions = new String[] { "--glue", "D:/citrus_works/citrus",
              "--plugin",
              
              "com.consol.citrus.cucumber.CitrusReporter",
              "D:/citrus_works/citrus/endtoend.feature" }; 
            
              int exitStatus =
              cucumber.api.cli.Main.run(cucumberOptions,
              Thread.currentThread().getContextClassLoader());//this line executes cucumber test case
        try {
            content = FileUtils.readFileToString(new File(path), StandardCharsets.UTF_8);
         
        } catch (IOException e) {
            e.printStackTrace();
        }

                return content;
    }
    
}

上面的class读取执行测试用例并将报告文件放在这个目录“D:\citrus\Report_Directory\citrus-test-results.html”

这是我的 spring 靴子 class

导入org.springframework.boot.SpringApplication;

@org.springframework.boot.autoconfigure.SpringBootApplication
public class SpringBootApplication {
    
    public static void main(String[] args) {
        SpringApplication.run(SpringBootApplication.class, args);
    }

}

虽然在 eclipse 中通过 rest 调用公开测试用例测试用例执行正常但是当我尝试在使用命令“spring-jar”构建 spring bootjar 后执行时,以下堆栈跟踪是出现

2020-09-14 17:41:16.938 ERROR 15668 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalArgumentException: name] with root cause

java.lang.IllegalArgumentException: name
        at java.base/jdk.internal.loader.URLClassPath$Loader.findResource(URLClassPath.java:603) ~[na:na]
        at java.base/jdk.internal.loader.URLClassPath.next(URLClassPath.java:344) ~[na:na]
        at java.base/jdk.internal.loader.URLClassPath.hasMoreElements(URLClassPath.java:354) ~[na:na]
        at java.base/java.net.URLClassLoader.run(URLClassLoader.java:651) ~[na:na]
        at java.base/java.net.URLClassLoader.run(URLClassLoader.java:649) ~[na:na]
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:391) ~[na:na]
        at java.base/java.net.URLClassLoader.next(URLClassLoader.java:648) ~[na:na]
        at java.base/java.net.URLClassLoader.hasMoreElements(URLClassLoader.java:673) ~[na:na]
        at org.springframework.boot.loader.LaunchedURLClassLoader$UseFastConnectionExceptionsEnumeration.hasMoreElements(LaunchedURLClassLoader.java:198) ~[citrus-integration-test-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
        at java.base/java.lang.CompoundEnumeration.next(ClassLoader.java:3042) ~[na:na]
        at java.base/java.lang.CompoundEnumeration.hasMoreElements(ClassLoader.java:3051) ~[na:na]
        at java.base/java.lang.CompoundEnumeration.next(ClassLoader.java:3042) ~[na:na]
        at java.base/java.lang.CompoundEnumeration.hasMoreElements(ClassLoader.java:3051) ~[na:na]
        at cucumber.runtime.io.ClasspathResourceIterable.iterator(ClasspathResourceIterable.java:31) ~[cucumber-core-3.0.2.jar!/:na]
        at cucumber.runtime.io.ResourceLoaderClassFinder.getDescendants(ResourceLoaderClassFinder.java:22) ~[cucumber-core-3.0.2.jar!/:na]
        at cucumber.runtime.Reflections.instantiateSubclasses(Reflections.java:33) ~[cucumber-core-3.0.2.jar!/:na]
        at cucumber.runtime.Reflections.instantiateExactlyOneSubclass(Reflections.java:17) ~[cucumber-core-3.0.2.jar!/:na]
        at cucumber.runtime.Runtime.loadBackends(Runtime.java:86) ~[cucumber-core-3.0.2.jar!/:na]
        at cucumber.runtime.Runtime.<init>(Runtime.java:42) ~[cucumber-core-3.0.2.jar!/:na]
        at cucumber.api.cli.Main.run(Main.java:34) ~[cucumber-core-3.0.2.jar!/:na]
        at com.miracle.testing.FeatureController.executeFeature(FeatureController.java:35) ~[classes!/:0.0.1-SNAPSHOT]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:209) ~[spring-web-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102) ~[spring-webmvc-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:891) ~[spring-webmvc-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:991) ~[spring-webmvc-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:925) ~[spring-webmvc-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:974) ~[spring-webmvc-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:866) ~[spring-webmvc-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:635) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:851) ~[spring-webmvc-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:742) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:109) ~[spring-web-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) ~[spring-web-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) ~[spring-web-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-5.0.9.RELEASE.jar!/:5.0.9.RELEASE]
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:493) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:800) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:806) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130) ~[na:na]
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630) ~[na:na]
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-8.5.34.jar!/:8.5.34]
        at java.base/java.lang.Thread.run(Thread.java:832) ~[na:na]

--glue 选项无法处理文件路径。您应该使用指向要加载的步骤定义 类 的包名称。

详情请参考Cucumber文档