无法从命令提示符将 Spring Boot 应用程序作为可运行 jar 运行

Posted

技术标签:

【中文标题】无法从命令提示符将 Spring Boot 应用程序作为可运行 jar 运行【英文标题】:Not able run Spring boot application as runnable jar from command prompt 【发布时间】:2017-06-28 21:53:03 【问题描述】:

我可以从我的 Eclipse 中运行应用程序,但是当我创建 jar 时尝试从命令提示符运行它会给出错误。我正在使用 java 1.8 和 eclipse 开普勒

@SpringBootApplication
public class Application 
  public static void main(String[] args) 
    ApplicationContext app = SpringApplication.run(Application.class, args);
    Application application = app.getBean(Application.class);
    if (args != null && args.length > 0) 
        application.getAllApiByProject(args);
     else 
        System.out.print("No Arguments found.., Pass Project argument");
    
    final int exitCode = 0;
    ExitCodeGenerator exitCodeGenerator = new ExitCodeGenerator() 

        @Override
        public int getExitCode() 
            return exitCode;
        
    ;
    SpringApplication.exit(app, exitCodeGenerator);
    System.out.print("Closing App Spring boot");
 

public void getAllApiByProject(String[] args) 
    System.out.print("Opening App Spring boot");
     if (args != null && args.length == 1) 
        apiService.getAllApiByProject(args[0]);
      else 
        String apiId = args[1];
        apiService.getApiById(Integer.parseInt(apiId));
     
   

   @Autowired
   private ApplicationContext context;

   @Autowired
   private ApiService apiService;


我正在使用以下命令创建 jar

mvn package
mvn spring-boot:run

我遇到了错误

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122) [na:1.8.0_121]
    at java.util.concurrent.FutureTask.get(FutureTask.java:192) [na:1.8.0_121]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:911) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:890) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_121]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_121]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_121]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) [tomcat-embed-core-8.5.6.jar:8.5.6]
    ... 6 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [Pipeline[StandardEngine[Tomcat].StandardHost[localhost].StandardContext[]]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5099) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.6.jar:8.5.6]
    ... 6 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [org.apache.catalina.authenticator.NonLoginAuthenticator[]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardPipeline.startInternal(StandardPipeline.java:170) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.6.jar:8.5.6]
    ... 8 common frames omitted
Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
    at org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1125) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.6.jar:8.5.6]
    ... 10 common frames omitted

2017-02-10 21:00:24.422 ERROR 4844 --- [           main] org.apache.catalina.core.ContainerBase   : A child container failed during start

java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat].StandardHost[localhost]]
    at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_121]
    at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_121]
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:911) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) [tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.6.jar:8.5.6]

org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer。 在 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:535) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:177) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) [spring-context-4.3.5.RELEASE.jar:4.3.5.RELEASE] 在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) [spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 com.relevancelab.imdg.Application.main(Application.java:17) [classes/:na] 在 sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121] 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121] 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121] 在 java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121] 在 org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:507) [spring-boot-maven-plugin-1.4.3.RELEASE.jar:1.4.3.RELEASE] 在 java.lang.Thread.run(Thread.java:745) [na:1.8.0_121] 原因:org.apache.catalina.LifecycleException:无法启动组件 [StandardEngine[Tomcat].StandardHost[localhost]] 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) [tomcat-embed-core-8.5.6.jar:8.5.6] 在 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1403) ~[tomcat-embed-core-8.5.6.jar:8.5.6] 在 org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1393) ~[tomcat-embed-core-8.5.6.jar:8.5.6] 在 java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[na:1.8.0_121] 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) ~[na:1.8.0_121] 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) ~[na:1.8.0_121] ... 1 常用框架省略 原因:org.apache.catalina.LifecycleException:子容器在启动期间失败 在 org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-8.5.6.jar:8.5.6] 在 org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:890) ~[tomcat-embed-core-8.5.6.jar:8.5.6] 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.6.jar:8.5.6] ...省略了6个常用框架

2017-02-10 21:00:24.422  WARN 4844 --- [           main] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
2017-02-10 21:00:24.423  INFO 4844 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2017-02-10 21:00:24.431 ERROR 4844 --- [           main] o.s.boot.SpringApplication               : Application startup failed

org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
    at com.relevancelab.imdg.Application.main(Application.java:17) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:507) [spring-boot-maven-plugin-1.4.3.RELEASE.jar:1.4.3.RELEASE]
    at java.lang.Thread.run(Thread.java:745) [na:1.8.0_121]
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:115) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.<init>(TomcatEmbeddedServletContainer.java:82) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getTomcatEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:535) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory.getEmbeddedServletContainer(TomcatEmbeddedServletContainerFactory.java:177) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.createEmbeddedServletContainer(EmbeddedWebApplicationContext.java:164) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
    ... 14 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardServer[-1]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.startup.Tomcat.start(Tomcat.java:356) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:96) ~[spring-boot-1.4.3.RELEASE.jar:1.4.3.RELEASE]
    ... 19 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardService[Tomcat]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:791) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    ... 21 common frames omitted
Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Tomcat]]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    ... 23 common frames omitted
Caused by: org.apache.catalina.LifecycleException: A child container failed during start
    at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    ... 25 common frames omitted

[WARNING] 
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.maven.AbstractRunMojo$LaunchRunner.run(AbstractRunMojo.java:507)
    at java.lang.Thread.run(Thread.java:745)
Caused by: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536)
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122)
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761)
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175)
    at com.relevancelab.imdg.Application.main(Application.java:17)
    ... 6 more
Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat

在 org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:134) ... 14 更多 原因:org.apache.catalina.LifecycleException:无法启动组件 [StandardServer[-1]] 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) 在 org.apache.catalina.startup.Tomcat.start(Tomcat.java:356) 在 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer.initialize(TomcatEmbeddedServletContainer.java:96) ... 19 更多 原因:org.apache.catalina.LifecycleException:无法启动组件 [StandardService[Tomcat]] 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) 在 org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:791) 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 21 更多 原因:org.apache.catalina.LifecycleException:无法启动组件 [StandardEngine[Tomcat]] 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167) 在 org.apache.catalina.core.StandardService.startInternal(StandardService.java:422) 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 23 更多 原因:org.apache.catalina.LifecycleException:子容器在启动期间失败 在 org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) 在 org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:262) 在 org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ... 25 更多 [错误] 未能执行目标 org.springframework.boot:spring-boot-maven-plugin :1.4.3.RELEASE:run (default-cli) on project IMDG: 运行时发生异常。空值: InvocationTargetException:无法启动嵌入式容器;嵌套异常是 org.springframework.boot.context.embedded.EmbeddedServletContainerException: 无法启动嵌入式 Tomcat: 无法启动组件 [标准 dServer[-1]]:无法启动组件 [StandardService[Tomcat]]:无法启动组件 [StandardEngine[Tomcat]]: 子容器在启动期间失败 -> 依赖树

[INFO] --- maven-dependency-plugin:2.10:tree (default-cli) @ IMDG ---
[INFO] relevancelab:IMDG:jar:1.0
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.4.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter:jar:1.4.3.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot:jar:1.4.3.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.4.3.RELEASE:compile
[INFO] |  |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.4.3.RELEASE:compile
[INFO] |  |  |  +- ch.qos.logback:logback-classic:jar:1.1.8:compile
[INFO] |  |  |  |  \- ch.qos.logback:logback-core:jar:1.1.8:compile
[INFO] |  |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.22:compile
[INFO] |  |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.22:compile
[INFO] |  |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.4.3.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.6:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.6:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.6:compile
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.3.3:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.5:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.5:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.5:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.3.5.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:4.3.5.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:1.4.3.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-aop:jar:1.4.3.RELEASE:compile
[INFO] |  |  \- org.aspectj:aspectjweaver:jar:1.8.9:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-jdbc:jar:1.4.3.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat:tomcat-jdbc:jar:8.5.6:compile
[INFO] |  |  |  \- org.apache.tomcat:tomcat-juli:jar:8.5.6:compile
[INFO] |  |  \- org.springframework:spring-jdbc:jar:4.3.5.RELEASE:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:5.0.11.Final:compile
[INFO] |  |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  |  +- org.javassist:javassist:jar:3.20.0-GA:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  +- org.jboss:jandex:jar:2.0.0.Final:compile
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  |  \- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] |  |  \- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] |  +- org.hibernate:hibernate-entitymanager:jar:5.0.11.Final:compile
[INFO] |  +- javax.transaction:javax.transaction-api:jar:1.2:compile
[INFO] |  +- org.springframework.data:spring-data-jpa:jar:1.10.6.RELEASE:compile
[INFO] |  |  +- org.springframework.data:spring-data-commons:jar:1.12.6.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-orm:jar:4.3.5.RELEASE:compile
[INFO] |  |  +- org.springframework:spring-tx:jar:4.3.5.RELEASE:compile
[INFO] |  |  \- org.slf4j:jcl-over-slf4j:jar:1.7.22:compile
[INFO] |  \- org.springframework:spring-aspects:jar:4.3.5.RELEASE:compile
[INFO] +- org.postgresql:postgresql:jar:9.4.1212.jre7:compile
[INFO] +- com.google.code.gson:gson:jar:2.7:compile
[INFO] +- org.apache.hadoop:hadoop-core:jar:2.6.0-mr1-cdh5.8.3:compile
[INFO] |  +- commons-cli:commons-cli:jar:1.2:compile
[INFO] |  +- xmlenc:xmlenc:jar:0.52:compile
[INFO] |  +- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] |  +- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  +- commons-net:commons-net:jar:3.1:compile
[INFO] |  +- org.mortbay.jetty:jetty:jar:6.1.26.cloudera.2:compile
[INFO] |  +- org.mortbay.jetty:jetty-util:jar:6.1.26.cloudera.2:compile
[INFO] |  +- tomcat:jasper-runtime:jar:5.5.23:compile
[INFO] |  +- tomcat:jasper-compiler:jar:5.5.23:compile
[INFO] |  +- org.codehaus.jackson:jackson-core-asl:jar:1.8.8:compile
[INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.8.8:compile
[INFO] |  +- javax.servlet.jsp:jsp-api:jar:2.1:compile
[INFO] |  +- commons-el:commons-el:jar:1.0:compile
[INFO] |  +- net.java.dev.jets3t:jets3t:jar:0.6.1:compile
[INFO] |  +- hsqldb:hsqldb:jar:1.8.0.10:compile
[INFO] |  +- org.eclipse.jdt:core:jar:3.1.1:compile
[INFO] |  \- org.apache.zookeeper:zookeeper:jar:3.4.5-cdh5.8.3:compile
[INFO] |     +- jline:jline:jar:2.11:compile
[INFO] |     \- org.jboss.netty:netty:jar:3.2.2.Final:compile
[INFO] +- org.apache.hive:hive-jdbc:jar:1.1.0-cdh5.4.0:compile
[INFO] |  +- org.apache.hive:hive-common:jar:1.1.0-cdh5.4.0:compile
[INFO] |  |  +- log4j:apache-log4j-extras:jar:1.2.17:compile
[INFO] |  |  \- org.apache.ant:ant:jar:1.9.1:compile
[INFO] |  |     \- org.apache.ant:ant-launcher:jar:1.9.1:compile
[INFO] |  +- org.apache.hive:hive-service:jar:1.1.0-cdh5.4.0:compile
[INFO] |  |  +- net.sf.jpam:jpam:jar:1.1:compile
[INFO] |  |  \- org.apache.thrift:libfb303:jar:0.9.2:compile
[INFO] |  +- org.apache.hive:hive-serde:jar:1.1.0-cdh5.4.0:compile
[INFO] |  |  +- net.sf.opencsv:opencsv:jar:2.3:compile
[INFO] |  |  \- com.twitter:parquet-hadoop-bundle:jar:1.5.0-cdh5.4.0:compile
[INFO] |  +- org.apache.hive:hive-metastore:jar:1.1.0-cdh5.4.0:compile
[INFO] |  |  +- com.jolbox:bonecp:jar:0.8.0.RELEASE:compile
[INFO] |  |  +- org.apache.derby:derby:jar:10.12.1.1:compile
[INFO] |  |  +- org.datanucleus:datanucleus-api-jdo:jar:3.2.6:compile
[INFO] |  |  +- org.datanucleus:datanucleus-core:jar:3.2.10:compile
[INFO] |  |  +- org.datanucleus:datanucleus-rdbms:jar:3.2.9:compile
[INFO] |  |  +- commons-pool:commons-pool:jar:1.6:compile
[INFO] |  |  +- commons-dbcp:commons-dbcp:jar:1.4:compile
[INFO] |  |  +- javax.jdo:jdo-api:jar:3.0.1:compile
[INFO] |  |  |  \- javax.transaction:jta:jar:1.1:compile
[INFO] |  |  \- org.antlr:antlr-runtime:jar:3.4:compile
[INFO] |  |     \- org.antlr:stringtemplate:jar:3.2.1:compile
[INFO] |  +- org.apache.hive:hive-shims:jar:1.1.0-cdh5.4.0:compile
[INFO] |  |  +- org.apache.hive.shims:hive-shims-common:jar:1.1.0-cdh5.4.0:compile
[INFO] |  |  +- org.apache.hive.shims:hive-shims-0.23:jar:1.1.0-cdh5.4.0:runtime
[INFO] |  |  |  \- org.apache.hadoop:hadoop-yarn-server-resourcemanager:jar:2.6.0-cdh5.4.0:runtime
[INFO] |  |  |     +- com.google.inject.extensions:guice-servlet:jar:3.0:runtime
[INFO] |  |  |     +- com.google.inject:guice:jar:3.0:runtime
[INFO] |  |  |     |  +- javax.inject:javax.inject:jar:1:runtime
[INFO] |  |  |     |  \- aopalliance:aopalliance:jar:1.0:runtime
[INFO] |  |  |     +- com.sun.jersey.contribs:jersey-guice:jar:1.9:runtime
[INFO] |  |  |     +- org.codehaus.jettison:jettison:jar:1.1:runtime
[INFO] |  |  |     +- org.apache.hadoop:hadoop-yarn-server-applicationhistoryservice:jar:2.6.0-cdh5.4.0:runtime
[INFO] |  |  |     \- org.apache.hadoop:hadoop-yarn-server-web-proxy:jar:2.6.0-cdh5.4.0:runtime
[INFO] |  |  \- org.apache.hive.shims:hive-shims-scheduler:jar:1.1.0-cdh5.4.0:runtime
[INFO] |  +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |  +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.5:compile
[INFO] |  +- org.apache.thrift:libthrift:jar:0.9.2:compile
[INFO] |  +- org.apache.curator:curator-framework:jar:2.6.0:compile
[INFO] |  +- org.slf4j:slf4j-api:jar:1.7.22:compile
[INFO] |  \- org.slf4j:slf4j-log4j12:jar:1.7.22:compile
[INFO] +- org.apache.hadoop:hadoop-common:jar:2.7.3:compile
[INFO] |  +- org.apache.hadoop:hadoop-annotations:jar:2.7.3:compile
[INFO] |  |  \- jdk.tools:jdk.tools:jar:1.8:system
[INFO] |  +- com.google.guava:guava:jar:11.0.2:compile
[INFO] |  +- org.apache.commons:commons-math3:jar:3.1.1:compile
[INFO] |  +- commons-io:commons-io:jar:2.4:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] |  +- log4j:log4j:jar:1.2.17:compile
[INFO] |  +- commons-lang:commons-lang:jar:2.6:compile
[INFO] |  +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] |  |  +- commons-digester:commons-digester:jar:2.1:compile
[INFO] |  |  |  \- commons-beanutils:commons-beanutils:jar:1.9.3:compile
[INFO] |  |  \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
[INFO] |  +- org.apache.avro:avro:jar:1.7.4:compile
[INFO] |  |  +- com.thoughtworks.paranamer:paranamer:jar:2.3:compile
[INFO] |  |  \- org.xerial.snappy:snappy-java:jar:1.0.4.1:compile
[INFO] |  +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
[INFO] |  +- org.apache.hadoop:hadoop-auth:jar:2.7.3:compile
[INFO] |  |  \- org.apache.directory.server:apacheds-kerberos-codec:jar:2.0.0-M15:compile
[INFO] |  |     +- org.apache.directory.server:apacheds-i18n:jar:2.0.0-M15:compile
[INFO] |  |     +- org.apache.directory.api:api-asn1-api:jar:1.0.0-M20:compile
[INFO] |  |     \- org.apache.directory.api:api-util:jar:1.0.0-M20:compile
[INFO] |  +- org.apache.curator:curator-client:jar:2.7.1:compile
[INFO] |  +- org.apache.curator:curator-recipes:jar:2.7.1:compile
[INFO] |  +- com.google.code.findbugs:jsr305:jar:3.0.0:compile
[INFO] |  +- org.apache.htrace:htrace-core:jar:3.1.0-incubating:compile
[INFO] |  \- org.apache.commons:commons-compress:jar:1.4.1:compile
[INFO] |     \- org.tukaani:xz:jar:1.0:compile
[INFO] +- org.apache.hadoop:hadoop-client:jar:2.7.3:compile
[INFO] |  +- org.apache.hadoop:hadoop-hdfs:jar:2.7.3:compile
[INFO] |  |  +- io.netty:netty:jar:3.6.2.Final:compile
[INFO] |  |  +- io.netty:netty-all:jar:4.0.23.Final:compile
[INFO] |  |  +- xerces:xercesImpl:jar:2.9.1:compile
[INFO] |  |  \- org.fusesource.leveldbjni:leveldbjni-all:jar:1.8:compile
[INFO] |  +- org.apache.hadoop:hadoop-mapreduce-client-app:jar:2.7.3:compile
[INFO] |  |  +- org.apache.hadoop:hadoop-mapreduce-client-common:jar:2.7.3:compile
[INFO] |  |  |  +- org.apache.hadoop:hadoop-yarn-client:jar:2.7.3:compile
[INFO] |  |  |  \- org.apache.hadoop:hadoop-yarn-server-common:jar:2.7.3:compile
[INFO] |  |  \- org.apache.hadoop:hadoop-mapreduce-client-shuffle:jar:2.7.3:compile
[INFO] |  +- org.apache.hadoop:hadoop-yarn-api:jar:2.7.3:compile
[INFO] |  +- org.apache.hadoop:hadoop-mapreduce-client-core:jar:2.7.3:compile
[INFO] |  |  \- org.apache.hadoop:hadoop-yarn-common:jar:2.7.3:compile
[INFO] |  |     +- javax.xml.bind:jaxb-api:jar:2.2.2:compile
[INFO] |  |     |  +- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |  |     |  \- javax.activation:activation:jar:1.1:compile
[INFO] |  |     +- javax.servlet:servlet-api:jar:2.5:compile
[INFO] |  |     +- com.sun.jersey:jersey-core:jar:1.9:compile
[INFO] |  |     +- com.sun.jersey:jersey-client:jar:1.9:compile
[INFO] |  |     +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.13:compile
[INFO] |  |     \- org.codehaus.jackson:jackson-xc:jar:1.9.13:compile
[INFO] |  \- org.apache.hadoop:hadoop-mapreduce-client-jobclient:jar:2.7.3:compile
[INFO] \- org.springframework:spring-web:jar:4.3.5.RELEASE:compile
[INFO]    +- org.springframework:spring-aop:jar:4.3.5.RELEASE:compile
[INFO]    +- org.springframework:spring-beans:jar:4.3.5.RELEASE:compile
[INFO]    +- org.springframework:spring-context:jar:4.3.5.RELEASE:compile
[INFO]    \- org.springframework:spring-core:jar:4.3.5.RELEASE:compile
[INFO] -------------------------------------------------------------------- 

【问题讨论】:

Tomcat 启动失败。之所以会在日志输出中。你能分享启动你的应用程序的所有输出吗? @AndyWilkinson,更新完整错误 @AndyWilkinson,我已经添加了依赖树,你能帮忙解决冲突吗,我试过但无法解决 【参考方案1】:

失败的根本原因是这样的:

Caused by: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getVirtualServerName()Ljava/lang/String;
    at org.apache.catalina.authenticator.AuthenticatorBase.startInternal(AuthenticatorBase.java:1125) ~[tomcat-embed-core-8.5.6.jar:8.5.6]
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [tomcat-embed-core-8.5.6.jar:8.5.6]
    ... 10 common frames omitted

这告诉我您在类路径上有一个旧版本(可能是 2.5)的 Servlet API。您使用的是 Tomcat 8.5.6,它是与 Servlet 3.1 兼容的服务器。使用mvn dependency:tree 确定旧的 Servlet API 被拉入的位置,然后将 &lt;exclusion&gt; 添加到您的 pom 以摆脱它。

【讨论】:

【参考方案2】:

maven package 不包含外部依赖项,因此,您可以将 jar 打包仅用作另一个项目的库。使用 spring boot maven 插件和 repackage 来打包可运行的 spring boot jars,如下所示:

mvn clean package spring-boot:repackage
java -jar target/spring-boot-project.jar

阅读这篇文章了解更多信息: https://www.baeldung.com/spring-boot-run-maven-vs-executable-jar

【讨论】:

以上是关于无法从命令提示符将 Spring Boot 应用程序作为可运行 jar 运行的主要内容,如果未能解决你的问题,请参考以下文章

当我将 Spring Boot 应用程序部署到 AWS Elastic Beanstalk 并且无法从本地 Spring Boot 连接到 RDS 时出现 502 错误网关

无法使用命令行参数启动 Spring Boot 应用程序

无法使用命令行参数启动 Spring Boot 应用程序

Spring Boot 从命令行执行将文件添加到类路径

无法在 Spring Boot 中加载外部属性

从命令行启动应用程序时,如何将 Spring Boot 应用程序 jar 中的文件作为 -D 属性值引用?