无法在 .WAR 文件中启动 Web 应用程序:java.lang.ClassNotFoundException
Can't start web application in .WAR file : java.lang.ClassNotFoundException
我有一个用 Groovy 编写的 grails 应用程序。它在使用 :
启动时构建并运行
./gradlew bootRun
现在我想 运行 将其与 java 一起放入 Docker 容器中。这是我准备的Docker文件:
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=build/libs/*.war
ADD ${JAR_FILE} app.war
ENTRYPOINT ["java"]
CMD ["-Dgrails.env=development","-jar","app.war"]
由于以下错误,服务器无法启动:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is java.lang.ClassNotFoundException: com.flosslab.eGrocery.showcase.CmsTagLib
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 29 more
Caused by: java.lang.ClassNotFoundException: com.flosslab.eGrocery.showcase.CmsTagLib
当我检查WEB-INF中的classes文件夹时,我发现class在正确的路径中。我尝试使用 Tomcat 设置,使用 Docker 和不使用 Docker,但我仍然遇到完全相同的错误。我认为 .WAR 构建有问题。这是 build.gradle 文件
build.gradle:
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/core" }
maven { url "https://repo.grails.org/grails/core" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0"
// classpath "org.grails.plugins:hibernate4:5.0.2"
classpath 'org.springframework:springloaded:1.2.8.RELEASE'
classpath "gradle.plugin.com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
}
}
version "1.0.49"
group "com.flosslab.egrocery"
apply plugin: "com.github.ManifestClasspath"
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
apply plugin: "asset-pipeline"
war.archiveName = "egrocery-showcase.war"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/core" }
maven { url "https://repo.grails.org/grails/core" }
maven { url "http://192.168.12.16:8081/artifactory/egrocery-local" }
maven { url "http://192.168.12.16:8081/artifactory/libs-release-local" }
maven { url "http://192.168.12.16:8081/artifactory/plugins-release-local" }
mavenCentral()
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
def elasticsearchVersion = '5.6.8'
ext['elasticsearch.version'] = elasticsearchVersion
dependencies {
compile fileTree(dir: "libs", includes: ["*.jar"])
compile "com.flosslab.egrocery:domain:1.0.49"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-core"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-datastore-rest-client:5.0.3.RELEASE"
console "org.grails:grails-console"
profile "org.grails.profiles:web:$grailsVersion"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.grails.plugins:spring-security-rest:2.0.0.M2"
compile "org.grails.plugins:spring-security-rest-gorm:2.0.0.M2"
runtime "org.grails.plugins:asset-pipeline"
runtime group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.7'
runtime group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.7'
// compile group: 'org.elasticsearch', name: 'elasticsearch', version: elasticsearchVersion
// compile group: 'org.elasticsearch.client', name: 'transport', version: elasticsearchVersion
// compile "org.grails.plugins:elasticsearch:1.4.1"
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:cache-ehcache:3.0.0.BUILD-SNAPSHOT"
compile "net.sf.ehcache:ehcache:2.10.2.2.21"
compile "net.sf.ehcache:ehcache-core:2.6.11"
compile "com.google.code.maven-play-plugin.net.tanesha.recaptcha4j:recaptcha4j:0.0.8"
runtime group: "org.postgresql", name: "postgresql", version: "42.1.4"
compile group: "net.java.dev.jna", name: "platform", version: "3.5.0"
compile group: "com.nimbusds", name: "nimbus-jose-jwt", version: "4.8"
compile group: "org.pac4j", name: "pac4j-core", version: "1.8.3"
compile "org.grails.plugins:fields"
testCompile "org.grails:grails-plugin-testing"
// testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}
configurations {
all {
exclude module: "bcmail-jdk14"
exclude module: "bctsp-jdk14"
exclude group: "com.google.guava", module: "guava"
exclude group: "com.google.guava", module: "guava-base"
}
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
gradle.properties:
grailsVersion=3.1.8
gradleWrapperVersion=2.11
也许 grails/groovy 版本缺少某些东西或有问题?我被困了一整天,非常感谢你的帮助。
更新:
这是我用我之前提到的 Tomcat 尝试的 Docker 文件。它给了我完全相同的错误。
FROM tomcat:8.5.75-jdk8-temurin
COPY egrocery-showcase.war /usr/local/tomcat/webapps
CMD ["catalina.sh", "run"]
我不敢相信我在这上面浪费了两天时间,因为有人用大写字母写了包裹。包裹里有一个class :
package com.flosslab.eGrocery.showcase
当我把它改成
package com.flosslab.egrocery.showcase
我克服了这个错误。
我有一个用 Groovy 编写的 grails 应用程序。它在使用 :
启动时构建并运行./gradlew bootRun
现在我想 运行 将其与 java 一起放入 Docker 容器中。这是我准备的Docker文件:
FROM openjdk:8-jdk-alpine
ARG JAR_FILE=build/libs/*.war
ADD ${JAR_FILE} app.war
ENTRYPOINT ["java"]
CMD ["-Dgrails.env=development","-jar","app.war"]
由于以下错误,服务器无法启动:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [grails.boot.config.GrailsApplicationPostProcessor]: Factory method 'grailsApplicationPostProcessor' threw exception; nested exception is java.lang.ClassNotFoundException: com.flosslab.eGrocery.showcase.CmsTagLib
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
... 29 more
Caused by: java.lang.ClassNotFoundException: com.flosslab.eGrocery.showcase.CmsTagLib
当我检查WEB-INF中的classes文件夹时,我发现class在正确的路径中。我尝试使用 Tomcat 设置,使用 Docker 和不使用 Docker,但我仍然遇到完全相同的错误。我认为 .WAR 构建有问题。这是 build.gradle 文件
build.gradle:
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/core" }
maven { url "https://repo.grails.org/grails/core" }
maven { url "https://plugins.gradle.org/m2/" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0"
// classpath "org.grails.plugins:hibernate4:5.0.2"
classpath 'org.springframework:springloaded:1.2.8.RELEASE'
classpath "gradle.plugin.com.github.viswaramamoorthy:gradle-util-plugins:0.1.0-RELEASE"
}
}
version "1.0.49"
group "com.flosslab.egrocery"
apply plugin: "com.github.ManifestClasspath"
apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
apply plugin: "asset-pipeline"
war.archiveName = "egrocery-showcase.war"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/core" }
maven { url "https://repo.grails.org/grails/core" }
maven { url "http://192.168.12.16:8081/artifactory/egrocery-local" }
maven { url "http://192.168.12.16:8081/artifactory/libs-release-local" }
maven { url "http://192.168.12.16:8081/artifactory/plugins-release-local" }
mavenCentral()
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
def elasticsearchVersion = '5.6.8'
ext['elasticsearch.version'] = elasticsearchVersion
dependencies {
compile fileTree(dir: "libs", includes: ["*.jar"])
compile "com.flosslab.egrocery:domain:1.0.49"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-starter-actuator"
provided "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-core"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-datastore-rest-client:5.0.3.RELEASE"
console "org.grails:grails-console"
profile "org.grails.profiles:web:$grailsVersion"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.grails.plugins:spring-security-rest:2.0.0.M2"
compile "org.grails.plugins:spring-security-rest-gorm:2.0.0.M2"
runtime "org.grails.plugins:asset-pipeline"
runtime group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.7'
runtime group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.7'
// compile group: 'org.elasticsearch', name: 'elasticsearch', version: elasticsearchVersion
// compile group: 'org.elasticsearch.client', name: 'transport', version: elasticsearchVersion
// compile "org.grails.plugins:elasticsearch:1.4.1"
compile group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13'
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:cache-ehcache:3.0.0.BUILD-SNAPSHOT"
compile "net.sf.ehcache:ehcache:2.10.2.2.21"
compile "net.sf.ehcache:ehcache-core:2.6.11"
compile "com.google.code.maven-play-plugin.net.tanesha.recaptcha4j:recaptcha4j:0.0.8"
runtime group: "org.postgresql", name: "postgresql", version: "42.1.4"
compile group: "net.java.dev.jna", name: "platform", version: "3.5.0"
compile group: "com.nimbusds", name: "nimbus-jose-jwt", version: "4.8"
compile group: "org.pac4j", name: "pac4j-core", version: "1.8.3"
compile "org.grails.plugins:fields"
testCompile "org.grails:grails-plugin-testing"
// testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}
configurations {
all {
exclude module: "bcmail-jdk14"
exclude module: "bctsp-jdk14"
exclude group: "com.google.guava", module: "guava"
exclude group: "com.google.guava", module: "guava-base"
}
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
gradle.properties:
grailsVersion=3.1.8
gradleWrapperVersion=2.11
也许 grails/groovy 版本缺少某些东西或有问题?我被困了一整天,非常感谢你的帮助。
更新: 这是我用我之前提到的 Tomcat 尝试的 Docker 文件。它给了我完全相同的错误。
FROM tomcat:8.5.75-jdk8-temurin
COPY egrocery-showcase.war /usr/local/tomcat/webapps
CMD ["catalina.sh", "run"]
我不敢相信我在这上面浪费了两天时间,因为有人用大写字母写了包裹。包裹里有一个class :
package com.flosslab.eGrocery.showcase
当我把它改成
package com.flosslab.egrocery.showcase
我克服了这个错误。