在我的Spring Boot项目开发的早期阶段,我习惯使用java -jar build \ libs \ online_store-0.1.0.jar来运行应用程序。现在我需要提供一个WAR。我按照下面的链接使用Gradle构建可部署的WAR文件。之后,我能够在Tomcat 8 webapp目录上部署生成的构建文件,并且工作正常。但我还需要使用java -jar运行嵌入式服务器。每次我尝试这样做(java -jar build \ libs \ online_store-0.1.0.war)我得到一个与一些缺少的依赖JAR相关的FileNotFoundException(请参阅下面的堆栈跟踪)。在我将相应的依赖项添加到requiresUnpack选项后,错误消息会更改但我恐怕永远不会完成添加依赖项。为了让WAR文件既可以部署又可以由java -jar运行,我缺少什么?提前谢谢。
requiresUnpack = [ "org.webjars:less", "org.webjars:jshint", "org.webjars:emberjs",
"org.webjars:handlebars", "org.webjars:coffee-script", "org.webjars:jslint", "org.webjars:json2",
"org.webjars:jquery", "org.webjars:handlebars", "org.slf4j:slf4j-api"
]
堆栈跟踪片段:
Caused by: java.lang.RuntimeException: java.io.FileNotFoundException: C:\Users\hcorzo\workspace\online_mvp\online_store\build\libs\online_store-0.1.0.war!\WEB-INF\lib\validate.js-0.8.0.jar (The system cannot find the path specified)
at org.webjars.urlprotocols.JarUrlProtocolHandler.getAssetPaths(JarUrlProtocolHandler.java:54)
at org.webjars.WebJarAssetLocator.getAssetPaths(WebJarAssetLocator.java:91)
at org.webjars.WebJarAssetLocator.getFullPathIndex(WebJarAssetLocator.java:121)
at org.webjars.WebJarAssetLocator.<init>(WebJarAssetLocator.java:152)
at org.springframework.web.servlet.resource.WebJarsResourceResolver.<init>(WebJarsResourceResolver.java:52)
at org.springframework.web.servlet.config.annotation.ResourceChainRegistration.getResourceResolvers(ResourceChainRegistration.java:108)
at org.springframework.web.servlet.config.annotation.ResourceHandlerRegistration.getRequestHandler(ResourceHandlerRegistration.java:164)
at org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry.getHandlerMapping(ResourceHandlerRegistry.java:113)
at org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport.resourceHandlerMapping(WebMvcConfigurationSupport.java:409)
at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$7c82d476.CGLIB$resourceHandlerMapping$33(<generated>)
at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$7c82d476$$FastClassBySpringCGLIB$$7c23c9ca.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:356)
at org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration$$EnhancerBySpringCGLIB$$7c82d476.resourceHandlerMapping(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 25 more
Caused by: java.io.FileNotFoundException: C:\Users\hcorzo\workspace\online_mvp\online_store\build\libs\online_store-0.1.0.war!\WEB-INF\lib\validate.js-0.8.0.jar (The system cannot find the path specified)
at java.util.zip.ZipFile.open(Native Method)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.zip.ZipFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at java.util.jar.JarFile.<init>(Unknown Source)
at org.webjars.urlprotocols.JarUrlProtocolHandler.getAssetPaths(JarUrlProtocolHandler.java:36)
... 43 more
这是我的build.gradle文件:
buildscript {
repositories {
mavenCentral()
jcenter()
maven { url 'http://dl.bintray.com/sbuettner/maven' }
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
classpath 'ro.isdc.wro4j.gradle:wro4j-gradle-plugin:1.8.0.Beta3'
classpath "io.spring.gradle:dependency-management-plugin:0.5.6.RELEASE"
}
}
apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'wro4j'
apply plugin: "io.spring.dependency-management"
apply plugin: 'war'
dependencyManagement {
imports {
mavenBom 'org.springframework.cloud:spring-cloud-netflix:1.1.0.RELEASE'
}
}
jar {
baseName = 'online_store'
version = '0.1.0'
}
war {
baseName = 'online_store'
version = '0.1.0'
}
repositories {
mavenCentral()
maven { url 'http://dl.bintray.com/sbuettner/maven' }
maven { url "http://repo.spring.io/libs-snapshot" }
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
ext {
versionJQuery = '2.1.1'
versionBootstrap = '3.2.0'
versionAngular = '1.3.8'
}
springBoot {
mainClass = "com.grupomedicus.store.server.UiApplication"
executable = true
requiresUnpack = [ "org.webjars:less", "org.webjars:jshint", "org.webjars:emberjs",
"org.webjars:handlebars", "org.webjars:coffee-script", "org.webjars:jslint", "org.webjars:json2",
"org.webjars:jquery", "org.webjars:handlebars", "org.slf4j:slf4j-api"
]
}
bootRepackage {
mainClass = "com.grupomedicus.store.server.UiApplication"
}
bootRun {
addResources = true
}
configurations {
providedRuntime
}
webResources {
bundle ('core') {
js 'js/**/*.js'
preProcessor 'jsMin'
}
bundle ('angular-bootstrap') {
js "webjars/jquery/$versionJQuery/jquery.min.js"
js "webjars/angularjs/$versionAngular/angular.min.js"
js "webjars/angularjs/$versionAngular/angular-route.min.js"
}
bundle ('angular-bootstrap') {
css "webjars/bootstrap/$versionBootstrap/css/bootstrap.min.css"
css 'themes/default/main.css'
cssRewriteUrl()
}
assets {
include 'themes/default/images/**'
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-security')
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.security:spring-security-core")
compile 'org.apache.commons:commons-lang3'
compile(group: 'de.infinit', name: 'spring-boot-autoconfigure-wro4j', version: '0.0.6')
compile "org.springframework.boot:spring-boot-starter-redis"
compile "org.springframework.session:spring-session"
compile "org.springframework.cloud:spring-cloud-starter-zuul"
webjars "org.webjars:jquery:$versionJQuery"
webjars "org.webjars:angularjs:$versionAngular"
webjars "org.webjars:bootstrap:$versionBootstrap"
testCompile("org.springframework.boot:spring-boot-starter-test")
testCompile("junit:junit")
runtime('mysql:mysql-connector-java:5.1.6')
}
task wrapper(type: Wrapper) {
gradleVersion = '2.13'
}