Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 当使用gradle构建spring boot应用程序时,如何在eclipse之外的spring boot应用程序中运行可执行jar文件?_Spring Boot_Build.gradle_Executable Jar - Fatal编程技术网

Spring boot 当使用gradle构建spring boot应用程序时,如何在eclipse之外的spring boot应用程序中运行可执行jar文件?

Spring boot 当使用gradle构建spring boot应用程序时,如何在eclipse之外的spring boot应用程序中运行可执行jar文件?,spring-boot,build.gradle,executable-jar,Spring Boot,Build.gradle,Executable Jar,我能够使用EclipseIDE运行SpringBoot(使用GradleBuild)应用程序,并且运行该应用程序没有任何问题 我现在尝试使用如下命令行运行相同的应用程序-java-jar foodapp,我得到的输出与在Eclipse中运行时得到的输出类似,如下所示: Sandeeps MacBook Pro:libs SandePamarnath$java-jar foodapp-0.0.1-SNAPSHOT.jar . ____ _ __ _ _

我能够使用EclipseIDE运行SpringBoot(使用GradleBuild)应用程序,并且运行该应用程序没有任何问题

我现在尝试使用如下命令行运行相同的应用程序-
java-jar foodapp
,我得到的输出与在Eclipse中运行时得到的输出类似,如下所示:

Sandeeps MacBook Pro:libs SandePamarnath$
java-jar foodapp-0.0.1-SNAPSHOT.jar

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

2019-09-12 20:20:17.292  INFO 785 --- [           main] c.s.foodapp.FoodappApplication           : Starting FoodappApplication on Sandeeps-MacBook-Pro.local with PID 785 (/Users/sandeepamarnath/Desktop/ShareMyRecipe-Java/foodapp/build/libs/foodapp-0.0.1-SNAPSHOT.jar started by sandeepamarnath in /Users/sandeepamarnath/Desktop/ShareMyRecipe-Java/foodapp/build/libs)
2019-09-12 20:20:17.295  INFO 785 --- [           main] c.s.foodapp.FoodappApplication           : No active profile set, falling back to default profiles: default
2019-09-12 20:20:17.797  INFO 785 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.
2019-09-12 20:20:17.863  INFO 785 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 59ms. Found 2 repository interfaces.
2019-09-12 20:20:18.184  INFO 785 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$df477ee1] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-09-12 20:20:18.455  INFO 785 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2019-09-12 20:20:18.485  INFO 785 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2019-09-12 20:20:18.485  INFO 785 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-09-12 20:20:18.737  INFO 785 --- [           main] org.apache.jasper.servlet.TldScanner     : At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
2019-09-12 20:20:18.901  INFO 785 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2019-09-12 20:20:18.901  INFO 785 --- [           main] o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 1572 ms
2019-09-12 20:20:19.128  INFO 785 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2019-09-12 20:20:19.868  INFO 785 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2019-09-12 20:20:19.919  INFO 785 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2019-09-12 20:20:19.992  INFO 785 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.3.10.Final}
2019-09-12 20:20:19.994  INFO 785 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2019-09-12 20:20:20.164  INFO 785 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.4.Final}
2019-09-12 20:20:20.441  INFO 785 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-09-12 20:20:22.047  INFO 785 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-09-12 20:20:22.705  INFO 785 --- [           main] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: any request, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@2a79d4b1, org.springframework.security.web.context.SecurityContextPersistenceFilter@7d42c224, org.springframework.security.web.header.HeaderWriterFilter@20b12f8a, org.springframework.security.web.csrf.CsrfFilter@544820b7, org.springframework.security.web.authentication.logout.LogoutFilter@23d1e5d0, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@68ad99fe, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@522a32b1, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@5ddea849, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@2e9fda69, org.springframework.security.web.session.SessionManagementFilter@2e554a3b, org.springframework.security.web.access.ExceptionTranslationFilter@2e61d218, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@3f6db3fb]
2019-09-12 20:20:22.859  INFO 785 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2019-09-12 20:20:22.908  WARN 785 --- [           main] aWebConfiguration$JpaWebMvcConfiguration : spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
2019-09-12 20:20:23.140  INFO 785 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2019-09-12 20:20:23.142  INFO 785 --- [           main] c.s.foodapp.FoodappApplication           : Started FoodappApplication in 21.143 seconds (JVM running for 21.485)
2019-09-12 20:20:35.404  INFO 785 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-09-12 20:20:35.404  INFO 785 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2019-09-12 20:20:35.411  INFO 785 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 7 ms
2019-09-12 20:20:35.579  INFO 785 --- [nio-8080-exec-1] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
但是,当我在浏览器中运行
localhost:8080
时,会出现如下错误

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Sep 12 20:20:40 EDT 2019
There was an unexpected error (type=Not Found, status=404).
/WEB-INF/view/index.jsp
虽然我在eclipse和命令行中收到了相同的消息,但当应用程序运行时,为什么我不能在命令行版本中第二次让浏览器工作呢。请让我知道我做错了什么。谢谢你抽出时间

我的gradle文件包含:

plugins {
    id 'org.springframework.boot' version '2.1.6.RELEASE'
    id 'java'
}


jar {
    manifest {
        attributes 'Main-Class': 'com.sharemyrecipe.foodapp.FoodappApplication.java'
    }
    from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
}


apply plugin: 'io.spring.dependency-management'

group = 'com.sharemyrecipe'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'

configurations {
    developmentOnly
    runtimeClasspath {
        extendsFrom developmentOnly
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-security'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    runtimeOnly 'mysql:mysql-connector-java'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    testImplementation 'org.springframework.security:spring-security-test'
    // https://mvnrepository.com/artifact/jstl/jstl
    compile group: 'jstl', name: 'jstl', version: '1.2'
    // https://mvnrepository.com/artifact/org.springframework.security/spring-security-taglibs
    compile group: 'org.springframework.security', name: 'spring-security-taglibs'
    // https://mvnrepository.com/artifact/org.apache.tomcat.embed/tomcat-embed-jasper
    compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper'
    // https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
    compile group: 'javax.servlet', name: 'javax.servlet-api'


}

我找到了我问题的答案,希望它能帮助别人。如中所述

在build.gradle文件中我添加了

task runFinalJar(type: JavaExec) {
   classpath = files('build/libs/foo.jar')
   classpath += sourceSets.main.runtimeClasspath
   main = 'com.sharemyrecipe.foodapp.FoodappApplication'
}
并在命令行中(gradlew所在的文件夹中)执行该命令

./gradlew runFinalJar
现在它运行得非常好。感谢尤金·马丁诺夫