I have a Gradle web application that I want to deploy on Tomcat 10.1
from within Eclipse.
I can successfully deploy the application when I manually run the war
task and placing it into the webapps
directory of my Tomcat installation, thus the project itself should be fine.
However, when I run the application from within Eclipse by Run As -> Run on Server
, I am getting ClassNotFoundException
s. I inspected the wtwebapps
directory and found that there is no lib
folder created under the WEB-INF
directory, so the dependencies are missing.
This is my build.gradle
file:
plugins {
id 'eclipse'
id 'war'
id 'java'
}
dependencies {
implementation project(':other-project')
compileOnly group: 'jakarta.platform', name: 'jakarta.jakartaee-api', version: '10.0.0'
compileOnly group: 'jakarta.servlet', name: 'jakarta.servlet-api', version: '6.0.0'
compileOnly 'jakarta.servlet.jsp:jakarta.servlet.jsp-api:3.1.0'
implementation 'org.glassfish.jersey.core:jersey-server:3.1.7'
implementation 'org.glassfish.jersey.media:jersey-media-json-jackson:3.1.7'
implementation 'org.glassfish.jersey.containers:jersey-container-servlet:3.1.7'
implementation group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: '3.1.7'
implementation 'org.apache.logging.log4j:log4j-core:2.23.1'
//...
}
war {
archiveName 'my-web.war'
}
My Project Facets View looks like this:
This is my web.xml
file:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns = "https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd" version="6.0">
<display-name>my-web</display-name>
</web-app>
This is my Deployment Assembly View:
With a Maven project, you could add “Maven Dependencies” here, but with Gradle, I see no such option.
What configuration is missing so that running the project on Tomcat within Eclipse will also include the dependencies folder in the WEB-INF/lib
folder?