如何在不使用STS的情况下启动jar文件

时间:2019-10-31 07:32:54

标签: spring-boot

我尝试做java -jar jarname.jar,但出现错误。

但是,如果我在STS上启动项目,则不会收到以前的错误。

我不明白为什么它不起作用,为什么STS可以工作,而jar也不起作用。

SLF4J: Found binding in [jar:file:/C:/Users/YSJ/Desktop/SJ/spring%20pj/scheduledPj/target/scheduledPj-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/C:/Users/YSJ/Desktop/SJ/spring%20pj/scheduledPj/target/scheduledPj-0.0.1-SNAPSHOT.jar!/BOOT-INF/lib/slf4j-log4j12-1.7.28.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v2.2.0.RELEASE)

2019-10-31 16:22:19.283  INFO 3952 --- [           main] com.scheduledPj.ScheduledPjApplication   : Starting ScheduledPjApplication v0.0.1-SNAPSHOT on KC20114 with PID 3952 (C:\Users\YSJ\Desktop\SJ\spring pj\scheduledPj\target\scheduledPj-0.0.1-SNAPSHOT.jar started by YSJ in C:\Users\YSJ\Desktop\SJ\spring pj\scheduledPj\target)
2019-10-31 16:22:19.289  INFO 3952 --- [           main] com.scheduledPj.ScheduledPjApplication   : No active profile set, falling back to default profiles: default
2019-10-31 16:22:20.284  WARN 3952 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.dao]' package. Please check your configuration.
2019-10-31 16:22:20.465  WARN 3952 --- [           main] o.m.s.mapper.ClassPathMapperScanner      : No MyBatis mapper was found in '[com.scheduledPj]' package. Please check your configuration.
2019-10-31 16:22:22.790  INFO 3952 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-10-31 16:22:22.801  INFO 3952 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-10-31 16:22:22.801  INFO 3952 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.27]
2019-10-31 16:22:22.899  INFO 3952 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-10-31 16:22:22.900  INFO 3952 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 3493 ms
2019-10-31 16:22:23.029  WARN 3952 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataController': Unsatisfied dependency expressed through field 'dataService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataService': Unsatisfied dependency expressed through field 'dataDao'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataDao': Unsatisfied dependency expressed through field 'sqlSession'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionTemplate' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionTemplate' parameter 0; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Unsatisfied dependency expressed through method 'sqlSessionFactory' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Failed to determine a suitable driver class
2019-10-31 16:22:23.035  INFO 3952 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-10-31 16:22:23.105  INFO 3952 --- [           main] ConditionEvaluationReportLoggingListener :

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-10-31 16:22:23.108 ERROR 3952 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

Failed to configure a DataSource: 'url' attribute is not specified and no embedded datasource could be configured.

Reason: Failed to determine a suitable driver class


Action:

Consider the following:
        If you want an embedded database (H2, HSQL or Derby), please put it on the classpath.
        If you have database settings to be loaded from a particular profile you may need to activate it (no profiles are currently active).

3 个答案:

答案 0 :(得分:0)

您做了任何特定的配置或设置吗?

答案 1 :(得分:0)

似乎在STS中,您已经以某种方式配置了参数url。如果使用java -jar启动应用程序,则还必须提供参数。例如:java -jar myspringbootapp.jar --url=jdbc:blabla

答案 2 :(得分:0)

Dependencies:<dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <scope>runtime</scope>
    <version>1.4.199</version>
</dependency>

Properties:
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect