I am having the following structure:
RootProject
|
----- Project1
|
----- Project2
|
------ WebAppStaging
The build.gradle of WebAppStaging is as below:
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
war {
baseName = 'MyApp'
webAppDirName = 'src/webapp'
}
//Ensure we copy all the required files to the WebAppStaging before creating war file
tasks.war.dependsOn(':Project2:copyMyFiles')
dependencies {
implementation project(':Project1')
implementation project(':Project2')
providedCompile 'javax.servlet:javax.servlet-api:3.1.0'
}
//Stop eclipse trying to find java source in the WebAppStaging project.
sourceSets {
main {
java.srcDirs = []
}
}
eclipse {
wtp {
facet {
facet name: "jst.web", version: "2.5" // Dynamic Web Application
facet name: "jst.jsf", version: "1.1" // Java Server Faces
}
}
}
This successfully generates the WAR.
I create a new Tomcat v8.5 server in Eclipse and add the WAR and start Tomcat.
I get the following error:
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContextListener
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 31 more
Doing a ctrl + shift + T on javax.servlet.ServletContextListener shows that the class is in Jar file servlet-api-3.1.0.jar
When I explode the WAR and see WEB_INF/lib directory, I do not see this jar in it. I do see, tomcat-servlet-api-8.5.35.jar however. I believe it is coming from the following dependency in Project2:
implementation 'org.apache.tomcat:tomcat-catalina:8.5.35'
How do I make this error go away during Tomcat start ?
I did do “Open Launch Configuration” on the server and added all the projects under UserEntries.
What am I missing?