I have a grails application written in Groovy. It is built and works when it's launched with :
./gradlew bootRun
Now I want to run it with java to put it in a Docker container. This is the Dockerfile I prepared :
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"]
The server fails to start because of the following error:
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
When I checked the classes folder in WEB-INF, I found that the class is there in the correct path. I tried with a Tomcat setup, with Docker and without Docker and I'm still encountering the exact same error. I think something is wrong with the .WAR build. Here is the build.gradle file
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
Maybe there is something is lacking or something is wrong with the grails/groovy version ? I'm stuck for the entire day so I would appreciate your help.
Update : Here is the Dockerfile I tried with Tomcat that I mentionned earlier. It gives me the exact same error.
FROM tomcat:8.5.75-jdk8-temurin
COPY egrocery-showcase.war /usr/local/tomcat/webapps
CMD ["catalina.sh", "run"]
CodePudding user response:
I can't believe I wasted two days straight on this because someone wrote the package with an uppercase letter. There was a class in a package :
package com.flosslab.eGrocery.showcase
When I changed it to
package com.flosslab.egrocery.showcase
I got past this error.