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

huangapple go评论66阅读模式
英文:

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

问题

以下是您提供的内容的翻译:

我有一个简单的特性控制器类,通过Rest调用公开了Cucumber测试用例。以下是控制器类:

@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()); // 这行执行Cucumber测试用例

        try {
            content = FileUtils.readFileToString(new File(path), StandardCharsets.UTF_8);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return content;
    }

}

上述类读取并执行测试用例,将报告文件放在此目录下:"D:\citrus\Report_Directory\citrus-test-results.html"

以下是我的Spring Boot类:

import org.springframework.boot.SpringApplication;

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

}

在Eclipse中通过Rest调用测试用例时,测试用例执行正常。但是,当我尝试使用命令"java -jar <jar名称>"构建Spring Boot JAR文件后执行时,会出现以下堆栈跟踪:

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]
    ...
    (堆栈跟踪的其余部分被省略)

注意:堆栈跟踪部分由于长度问题进行了省略。

英文:

I have simple feature controller class which exposes cucumber test cases over the Rest call. Here is the Controller class

    @RestController
@RequestMapping(&quot;/featureTest&quot;)
public class FeatureController {

	@RequestMapping(value=&quot;/MQEndtoEnd&quot;,produces = MediaType.TEXT_HTML_VALUE)
    public String executeFeature(@RequestParam(name = &quot;FeatureFileName&quot;) String featureFileName) 
      throws Throwable  {
		String path=&quot;D:\\citrus\\Report_Directory\\citrus-test-results.html&quot;;         
		 String content=&quot;&quot;;
	
			  String[] cucumberOptions = new String[] { &quot;--glue&quot;, &quot;D:/citrus_works/citrus&quot;,
			  &quot;--plugin&quot;,
			  
			  &quot;com.consol.citrus.cucumber.CitrusReporter&quot;,
			  &quot;D:/citrus_works/citrus/endtoend.feature&quot; }; 
			
			  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;
	}
	
}

The above class reads executes test cases and places report file in this directory "D:\citrus\Report_Directory\citrus-test-results.html"

Here is my spring boot class

import org.springframework.boot.SpringApplication;

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

}

While exposing the test case over rest call in eclipse Test case is executing fine but while I try to execute after building spring bootjar with command "java -jar <name of jar>" the follwing stack trace is appearing

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$1.next(URLClassPath.java:344) ~[na:na]
at java.base/jdk.internal.loader.URLClassPath$1.hasMoreElements(URLClassPath.java:354) ~[na:na]
at java.base/java.net.URLClassLoader$3$1.run(URLClassLoader.java:651) ~[na:na]
at java.base/java.net.URLClassLoader$3$1.run(URLClassLoader.java:649) ~[na:na]
at java.base/java.security.AccessController.doPrivileged(AccessController.java:391) ~[na:na]
at java.base/java.net.URLClassLoader$3.next(URLClassLoader.java:648) ~[na:na]
at java.base/java.net.URLClassLoader$3.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.&lt;init&gt;(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]

答案1

得分: 0

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

有关详细信息,请参阅Cucumber文档。

英文:

The - - glue option can not handle a file path. You should be using package names pointing to the step definition classes that you want to load instead.

Please refer to the Cucumber documentation for details

huangapple
  • 本文由 发表于 2020年9月14日 20:31:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/63884404.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定