Gradle Eclipse JSF Project java.lang.ClassNotFoundException javax.faces.webapp.FacesServlet - java

I am using the Gradle plugin in Eclipse to create a JSF project. I am running the project on Tomcat 9. When I attempt run on server in Eclipse, I get the java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet exception.
My gradle.build looks like this:
// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'
apply plugin: 'war'
apply plugin: 'eclipse'
apply plugin: 'eclipse-wtp'
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
api 'org.apache.commons:commons-math3:3.6.1'
implementation 'com.google.guava:guava:21.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
//Jersey
implementation 'org.glassfish.jersey.containers:jersey-container-servlet:2.26'
implementation 'org.glassfish.jersey.inject:jersey-hk2:2.26'
implementation 'org.glassfish.jersey.core:jersey-common:2.26'
//JAXB
implementation 'org.glassfish.jersey.media:jersey-media-json-jackson:2.26'
//Javax Servlet
implementation 'javax.servlet:javax.servlet-api:3.1.0'
//JSF
implementation 'org.glassfish:javax.faces:2.2.16'
}
eclipse {
wtp {
facet {
facet name: "java", version: "1.8" // Java version
facet name: "jst.web", version: "3.1" // Dynamic Web Application
facet name: "jst.jsf", version: "2.2" // Java Server Faces
facet name: "wst.jsdt.web", version: "1.0" // JavaScript
}
}
}
project.webAppDirName='WebContent'
My web.xml looks like this:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4" id="WebApp_ID">
<display-name>com.xxx</display-name>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
I can see that gradle has added the correct library to my resources:
I cannot think of anything else that could be wrong. Any help is appreciated.
UPDATE: If I build a WAR file from the project, and then import that WAR as a new Dynamic Web Project, it runs fine, with no errors. So, there is obviously some other issue going on here, probably related to Gradle.
UPDATE2:
Stack Trace:
SEVERE: Servlet [Faces Servlet] in web application [/com.foo.bar] threw load() exception
java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1104)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:540)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:521)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:150)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1032)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:971)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4765)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5075)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:839)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1427)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1417)
at java.util.concurrent.FutureTask.run(Unknown Source)
at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75)
at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:258)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardService.startInternal(StandardService.java:422)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:770)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183)
at org.apache.catalina.startup.Catalina.start(Catalina.java:682)
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.apache.catalina.startup.Bootstrap.start(Bootstrap.java:353)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:493)
Build Path:
Class location:

Changing "implementation" to "compile" for the required libraries fixed the issue.
/*
* This build file was generated by the Gradle 'init' task.
*
* This generated file contains a sample Java Library project to get you started.
* For more details take a look at the Java Libraries chapter in the Gradle
* user guide available at https://docs.gradle.org/3.5/userguide/java_library_plugin.html
*/
// Apply the java-library plugin to add support for Java Library
apply plugin: 'java-library'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
// In this section you declare where to find the dependencies of your project
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
}
dependencies {
// This dependency is exported to consumers, that is to say found on their compile classpath.
api 'org.apache.commons:commons-math3:3.6.1'
// This dependency is used internally, and not exposed to consumers on their own compile classpath.
implementation 'com.google.guava:guava:21.0'
// Use JUnit test framework
testImplementation 'junit:junit:4.12'
//Jersey
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.26'
compile 'org.glassfish.jersey.inject:jersey-hk2:2.26'
compile 'org.glassfish.jersey.core:jersey-common:2.26'
//JAXB
compile 'org.glassfish.jersey.media:jersey-media-json-jackson:2.26'
//Javax Servlet
compile 'javax.servlet:javax.servlet-api:3.0.1'
//JSF
compile 'org.glassfish:javax.faces:2.2.16'
compile 'javax.inject:javax.inject:1'
compile 'org.glassfish.jersey.containers:jersey-container-servlet:2.25.1'
}
eclipse {
wtp {
facet {
facets = []
facet name: "java", version: "1.8" // Java version
facet name: "jst.web", version: "3.0" // Dynamic Web Application
facet name: "jst.jsf", version: "2.2" // Java Server Faces
facet name: "wst.jsdt.web", version: "1.0" // JavaScript
}
}
}
project.webAppDirName='WebContent'

Related

Spring Boot can not find AutoConfigurationReportLoggingInitializer

When I build my jar, I get ClassNotFoundException for AutoConfigurationReportLoggingInitializer.
This class is not in Spring libraries built by Gradle and also the class is not necessary for running in IDE. Is it possible to disable searching for this class? Or do you have some other solution?
EXCEPTION:
Caused by: java.lang.ClassNotFoundException: org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.springframework.util.ClassUtils.forName(ClassUtils.java:284)
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:438)
... 10 more
build.gradle:
plugins {
id 'org.springframework.boot' version '2.3.3.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'java'
}
repositories {
mavenCentral()
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
testCompile('org.springframework.boot:spring-boot-starter-test')
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.1'
}
Try adding the spring-boot-starter dependency which includes spring-boot-starter-logging which has the class you are missing

How to solve “Failed to instantiate WebApplicationInitializer class”Error running in Tomcat after war generation

Error running in Tomcat after war generation
How to solve “Failed to instantiate WebApplicationInitializer class”
Generating jars is operational
The changes i did in my gradle build file
2-Jul-2019 16:00:10.516 严重 [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Error during ServletContainerInitializer processing
javax.servlet.ServletException: Failed to instantiate WebApplicationInitializer class
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:155)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5267)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:754)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:730)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1140)
at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1875)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.InstantiationException: io.j99.app.measure.Application
at java.lang.Class.newInstance(Unknown Source)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:152)
... 12 more
Caused by: java.lang.NoSuchMethodException: io.j99.app.measure.Application.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
... 14 more
02-Jul-2019 16:00:10.516 严重 [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal Context [/measure-0.0.1] startup failed due to previous errors
02-Jul-2019 16:00:10.562 警告 [localhost-startStop-1] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [measure-0.0.1] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
02-Jul-2019 16:00:10.562 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [D:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\measure-0.0.1] has finished in [5,484] ms
02-Jul-2019 16:00:10.562 信息 [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [D:\Program Files\Apache Software Foundation\Tomcat 8.5\webapps\ROOT]
02-Jul-2019 16:00:10.734 信息 [36] org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load []. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1364)
at org.apache.catalina.loader.WebappClassLoaderBase.getResource(WebappClassLoaderBase.java:1021)
at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.checkContextClassLoaders(AbandonedConnectionCleanupThread.java:96)
at com.mysql.cj.jdbc.AbandonedConnectionCleanupThread.run(AbandonedConnectionCleanupThread.java:69)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
enter code here
The changes i did in my gradle build file
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
//apply plugin: 'spring-boot'
//apply plugin: 'watch'
apply plugin: 'war'
war {
baseName = 'measure'
version = '0.0.1'
}
/*apply plugin: 'idea'
idea {
module {
inheritOutputDirs = false
outputDir = file("$buildDir/classes/main/")
}
}*/
repositories {
maven { url "http://maven.aliyun.com/nexus/content/repositories/public/" }
maven { url "http://repo.spring.io/libs-snapshot" }
}
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
springBoot {
executable = true
}
configurations {
// providedRuntime
dev
}
/*jar {
mainClass = "io.j99.app.measure.Application"
}*/
dependencies {
compile("commons-logging:commons-logging:1.2")
compile("javax.servlet:javax.servlet-api:4.0.1")
//
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: '9.0.8'
compile("org.springframework.boot:spring-boot-devtools")
//
compile group: 'org.springframework.boot', name: 'spring-boot-dependencies', version: '2.2.0.M4'
compile group: 'org.springframework.boot', name: 'spring-boot-maven-plugin', version: '2.2.0.M4'
///
compile ("org.springframework.boot:spring-boot-dependencies")
compile ("org.springframework.boot:spring-boot-maven-plugin")
///
////
compile group: 'cn.org.faster', name: 'spring-boot-starter-parent', version: '1.1.1.RELEASE'
compile ("org.springframework.boot:spring-boot-starter-tomcat")
compile ("org.springframework.boot:spring-boot-starter-web")
compile ("org.springframework.boot:spring-boot-devtools")
//
compile "org.springframework.boot:spring-boot-configuration-processor"
compile("mysql:mysql-connector-java:8.0.12")
///
compile fileTree(dir: 'libs', include: ['*.jar'])
// dev("org.springframework.boot:spring-boot-devtools")
testCompile("org.springframework.boot:spring-boot-starter-test")
compile "io.springfox:springfox-swagger2:2.5.0"
compile("org.springframework.session:spring-session")
compile("org.simpleframework:simple-xml:2.7")
compile("org.springframework.boot:spring-boot-starter-thymeleaf")
compile("org.springframework.boot:spring-boot-starter-data-redis")
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile 'io.jsonwebtoken:jjwt:0.6.0'
// compile("org.springframework.boot:spring-boot-starter-data-mongodb")
compile("org.springframework.boot:spring-boot-starter-jdbc")
compile("org.springframework.boot:spring-boot-starter-data-jpa")
compile("org.springframework.boot:spring-boot-starter-actuator")
// compile("mysql:mysql-connector-java")
compile("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.6.0")
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-jackson:2.1.0'
compile 'com.squareup.retrofit2:adapter-rxjava:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.1.2'
compile 'com.squareup.okhttp3:okhttp:3.1.2'
compile("org.springframework.boot:spring-boot-starter-web")
compile('commons-net:commons-net:3.5')
compile('com.googlecode.log4jdbc:log4jdbc:1.2')
// https://mvnrepository.com/artifact/org.apache.poi/poi
compile group: 'org.apache.poi', name: 'poi', version: '3.15'
compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.15'
// https://mvnrepository.com/artifact/commons-lang/commons-lang
compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
compile 'com.qiniu:qiniu-java-sdk:7.2.2'
// https://mvnrepository.com/artifact/org.apache.ant/ant
compile group: 'org.apache.ant', name: 'ant', version: '1.10.1'
}
bootRun {
// addResources = true
classpath = sourceSets.main.runtimeClasspath + configurations.dev
}
War can be generated
Cannot run in Tomcat
Is it due to the lack of jar?
Please let me know how to resolve the same

org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start: org.apache.catalina.LifecycleException

I encountered this error when I tried to deployed war in tomcat with spring boot 2.1.2.My tomcat version is 8.5.14 and java is 1.8.0_121.I think i had done everything right and its working perfectly in my machine but its not working when i deploy it on server with below error.
08-May-2019 05:54:33.459 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/8.5.14
08-May-2019 05:54:33.462 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive /opt/apache-tomcat/webappsloop/LoopServer.war
08-May-2019 05:54:33.665 WARNING [localhost-startStop-1] org.apache.tomcat.util.descriptor.web.WebXml.setVersion Unknown version string [4.0]. Default version will be used.
08-May-2019 05:54:38.037 INFO [localhost-startStop-1] org.apache.jasper.servlet.TldScanner.scanJars 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.
08-May-2019 05:54:38.041 INFO [localhost-startStop-1] org.apache.catalina.core.ApplicationContext.log 2 Spring WebApplicationInitializers detected on classpath
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/apache-tomcat/webappsloop/LoopServer/WEB-INF/lib/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/apache-tomcat/webappsloop/LoopServer/WEB-INF/lib/logback-classic-1.1.11.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]
08-May-2019 05:54:38.231 SEVERE [localhost-startStop-1] org.apache.catalina.core.ContainerBase.addChildInternal ContainerBase.addChild: start:
org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Loop].StandardHost[localhost].StandardContext[/LoopServer]]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:167)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:752)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.IllegalArgumentException: Cannot instantiate interface org.springframework.boot.SpringApplicationRunListener : org.springframework.boot.context.event.EventPublishingRunListener
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:450)
at org.springframework.boot.SpringApplication.getSpringFactoriesInstances(SpringApplication.java:429)
at org.springframework.boot.SpringApplication.getRunListeners(SpringApplication.java:415)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:301)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.run(SpringBootServletInitializer.java:157)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:137)
at org.springframework.boot.web.servlet.support.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:91)
at org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:169)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5196)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 10 more
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.context.event.EventPublishingRunListener]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:184)
at org.springframework.boot.SpringApplication.createSpringFactoriesInstances(SpringApplication.java:446)
... 19 more
Caused by: java.lang.NoSuchMethodError: org.springframework.aop.framework.AopProxyUtils.getSingletonTarget(Ljava/lang/Object;)Ljava/lang/Object;
at org.springframework.context.event.AbstractApplicationEventMulticaster.addApplicationListener(AbstractApplicationEventMulticaster.java:109)
at org.springframework.boot.context.event.EventPublishingRunListener.<init>(EventPublishingRunListener.java:58)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:172)
... 20 more
08-May-2019 05:54:38.232 SEVERE [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Error deploying web application archive /opt/apache-tomcat/webappsloop/LoopServer.war
java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Loop].StandardHost[localhost].StandardContext[/LoopServer]]
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:756)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:728)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:734)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:952)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1823)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
08-May-2019 05:54:38.232 INFO [localhost-startStop-1] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive /opt/apache-tomcat/webappsloop/LoopServer.war has finished in 4,770 ms
Below is my build.gradle config
group 'com.lss.loopserver'
version '1.0-SNAPSHOT'
buildscript {
ext {
springBootVersion = '2.1.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}
apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'war'
war {
baseName = 'LoopServer'
version = '0.0.1'
}
sourceCompatibility = 1.8
repositories {
mavenCentral()
jcenter()
maven { url "http://repo.spring.io/libs-snapshot" }
}
dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-starter-data-jpa')
compile('org.springframework.boot:spring-boot-starter-security')
compile('org.springframework.cloud:spring-cloud-starter-oauth2')
compile 'org.springframework.boot:spring-boot-starter-aop'
compile('org.springframework.boot:spring-boot-starter-web')
compile('javax.inject:javax.inject:1')
compile ('mysql:mysql-connector-java:6.0.6')
compile ('com.google.code.gson:gson:2.8.1')
compile group: 'commons-fileupload', name: 'commons-fileupload', version: '1.3.3'
compile 'org.apache.commons:commons-io:1.3.2'
runtime('org.springframework.boot:spring-boot-devtools')
runtime('com.h2database:h2')
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testCompile('org.springframework.boot:spring-boot-starter-test')
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Greenwich.RC2"
}
}
bootRun {
sourceResources sourceSets.main
}
The Application class with main function as below.
#SpringBootApplication
public class Main extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Main.class);
}
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
NoSuchMethodError error, the most likely is the problem of the introduction of the jar package, or the jar package conflict.
You can look at the tree structure of the jar package through maven and see the dependencies after the jar package. If it is true that the jar package is missing, import the jar package, for example, Caused by: java.lang.NoSuchMethodError: org.springframework.aop.xxxxx.xxxxx. I will first look for the jar package that the project depends on. There is no such jar package exists, and then there is no such class, the method.
If not, you can add dependencies via the pom (maven configuration file) file. If this class exists, it is likely that the jar package conflicts.
For a jar package conflict, let's take a very simple example. If you reference the A.jar package and the B.jar package, both A and B depend on the C.jar package. However, A depends on the 1.1 version of the C.jar package, and B depends on the 2.1 version of the jar package. If your project is stored in version 1.1 at this time, it is very likely that an error will be reported.
Seems there is a dependency exclusion you should do ,
For Gradle (but not sure):
dependencies {
implementation('org.springframework.boot:spring-boot-starter-security:version) {
exclude group: 'org.springframework', module: 'spring-aop'
}
}
Maven way :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId></artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
</exclusions>
</dependency>
Refer the dependency sections of spring boot repos , seems to be transitive dependency issue https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-aop/2.1.2.RELEASE
https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-security/2.1.2.RELEASE
Also for the Tomcat part
dependencies {
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
}
providedRuntime group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: "2.1.2.RELEASE"
}

RepositoryRestMvcConfiguration cannot be cast to javax.servlet.Servlet

I am trying to deploy one war file to tomcat but the log file shows the following exception :
SEVERE: Servlet [rest] in web application [/sample] threw load() exception
java.lang.ClassCastException: org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration cannot be cast to javax.servlet.Servlet
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1148)
at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5253)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5543)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1095)
at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1930)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Here is the build.gradle file
repositories {
mavenCentral()
}
dependencies {
providedCompile 'org.apache.tomcat:tomcat-servlet-api:7.0.37'
providedCompile 'javax.servlet:javax.servlet-api:4.0.0-b01'
// Spring Framework Jars
compile 'org.springframework:spring-context:4.1.0'
compile 'org.springframework.ws:spring-ws-core:2.2.2.RELEASE'
compile 'org.springframework.data:spring-data-jpa:1.9.0.RELEASE'
// Spring Integration Jars
compile 'org.springframework.integration:spring-integration-core:4.1.2.RELEASE'
compile 'org.springframework.integration:spring-integration-stream:4.1.2.RELEASE'
compile 'org.springframework.integration:spring-integration-jms:4.1.2.RELEASE'
compile 'org.springframework.integration:spring-integration-xml:4.1.2.RELEASE'
compile 'org.springframework.integration:spring-integration-http:4.1.2.RELEASE'
compile 'org.springframework.integration:spring-integration-mail:4.1.2.RELEASE'
compile 'org.springframework:spring-webmvc:4.2.2.RELEASE'
compile 'org.springframework.data:spring-data-rest-webmvc:2.4.0.RELEASE'
// Spring Batch Framework Jars
compile 'org.springframework.batch:spring-batch-infrastructure:3.0.4.RELEASE'
compile 'org.springframework.batch:spring-batch-core:3.0.4.RELEASE'
// Log4j Jar
compile 'log4j:log4j:1.2.17'
// IBM JMS MQ Jars
compile 'com.ibm:com.ibm.mq:7.0.1.0'
compile 'com.ibm:com.ibm.mq.jmqi:7.0.1.0'
compile 'com.ibm:com.ibm.mqjms:7.0.1.0'
compile 'javax.jms:jms-api:1.1-rev-1'
// Hibernate JARS
compile 'org.hibernate:hibernate-entitymanager:5.0.1.Final'
//Oracle JDBC Jar
compile 'com.oracle:ojdbc6:11.2.0.3.0'
//Mail Jar
compile 'javax.mail:javax.mail-api:1.5.4'
}
And this is my web.xml file .
<web-app>
<display-name>sample Web Application</display-name>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/config/sample-servlet.xml</param-value>
</context-param>
<servlet>
<servlet-name>rest</servlet-name>
<servlet-class>org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>rest</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
I have tried to exclude "javax.servlet-api " ,but with no avail .
If anyone can help me in finding the reason behind this exception ,that would be of great help .
Thanks
Made a silly mistake ,instead of using
"org.springframework.data.rest.webmvc.RepositoryRestDispatcherServlet"
,i used
"org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration"
.
Hope after seeing this post other people will not make the same mistake

Migrating from existing dynamic web project to gradle

I am having an existing java dynamic web project which I created using eclipse. I usually just create a war file via eclipse and then deploy it to tomcat.
Now I want to use Gradle to build my project and create the war file. Is there an eclipse plugin to do that? If not then how can I use gradle with my existing project?
My existing project structure is what you get when you create a dynamic web project via eclipse and I don't want to change it.
I have tried going through tutorials and using converting to Gradle project using gradle plugin. Can someone atleast point to a blog or tutorial or a way to start things?
MyProject
|java resources
|--src
|-- -- packages
|-- -- .properties files
|--test
|-- -- packages
|build
|-- classes
|WebContent
|-- MetaINF
|-- WEB-INF
|-- -- lib // all my libraries are here. there is no specific repo for now
|-- -- web.xml
My build.gradle :
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'war'
sourceCompatibility = 1.7
targetCompatibility = 1.7
version = '2.0'
war {
baseName = 'Gradle'
version = '1.2'
}
repositories {
mavenCentral()
}
repositories {
flatDir {
dirs 'lib'
}
}
dependencies {
compile group: 'commons-collections', name: 'commons-collections', version: '3.2'
testCompile group: 'junit', name: 'junit', version: '4.+'
compile files('./lib/myjar.jar')
compile 'commons-codec:commons-codec:1.5'
compile 'commons-lang:commons-lang:2.6'
compile 'org.hibernate:hibernate-entitymanager:4.3.8.Final'
compile 'org.apache.axis2:axis2-kernel:1.6.2'
compile 'org.apache.axis2:axis2-adb:1.6.2'
compile 'com.sun.jersey:jersey-server:1.19'
compile 'com.sun.jersey:jersey-client:1.19'
compile 'log4j:log4j:1.2.17'
compile 'org.apache.axis2:axis2-transport-local:1.6.2'
compile 'org.apache.axis2:axis2-transport-http:1.6.2'
providedCompile 'javax.servlet:servlet-api:2.3'
testCompile 'junit:junit:4.9'
testCompile 'org.jmock:jmock:2.6.0'
testCompile 'org.jmock:jmock-junit4:2.6.0'
testCompile 'org.jmock:jmock-legacy:2.6.0'
}
test {
systemProperties 'property': 'value'
}
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>Gradle</display-name>
<servlet>
<servlet-name>HTTP REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
//in the above line It is showing a warning: servlet-class references to non-existent class "com.sun.jersey.spi.container.servlet.ServletContainer"
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>org.gradle</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HTTP REST Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
My proj structure
Here's a minimal build.gradle file that should get you going. Build with the command gradle war.
apply plugin: 'war'
// See http://gradle.org/docs/current/userguide/war_plugin.html
// Section 26.5. Convention properties
webAppDirName = 'WebContent'
// See http://gradle.org/docs/current/userguide/java_plugin.html
// Section 23.4.1. Changing the project layout
sourceSets {
main {
// where does the Java source code live?
java {
srcDir 'Java Resources/src'
}
// where do classpath resources like *.properties files live?
resources {
srcDir 'Java Resources/src'
}
}
}
// See http://gradle.org/docs/current/userguide/dependency_management.html
// Section 51.4.4. File dependencies
dependencies {
// Where do the JARs live on the filesystem?
compile fileTree(dir: "${webAppDirName}/WEB-INF/lib", include: '*.jar')
}

Categories

Resources