I’ve been facing a critical issue from past one week on jetty web application deployment can any one please assist me where I’m doing the wrong stuff?
Description:
-
I’m building a Spring Boot (version:2.7.8) web application using JDK 17 as per client requirement.
-
In order to deploy the application, I’m using Jetty server with jetty-maven-plugin artifact (version 11.0.21)
-
I’ve gone through the below documentation pages to configure jetty-web.xml
https://jetty.org/docs/jetty/11/operations-guide/deploy/index.html
https://jetty.org/docs/jetty/11/programming-guide/maven-jetty/jetty-maven-plugin.html#jetty-run-goal
Now when I’m starting jetty server using clean install and jetty:run from my IDE, the server goes up but it’s not detecting any WebApplicationInitializers on class path and due to this Spring Boot application is not getting initialized.
Logs:
[INFO] — jetty-maven-plugin:11.0.21:run (default-cli) @ demo —
[INFO] Configuring Jetty for project: demo
[INFO] Classes = /home/Downloads/demo/target/classes
[INFO] Context path = /
[INFO] Tmp directory = /home/Downloads/demo/target/tmp
[INFO] web.xml file = null
[INFO] Webapp directory = /home/Downloads/demo/src/main/webapp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] jetty-11.0.21; built: 2024-05-14T03:19:28.958Z; git: 996cd61addad9cb033e0e3eba6fa3f0fa3dc270d; jvm 17.0.11+9-Ubuntu-122.04.1
[INFO] Session workerName=node0
[INFO] Started o.e.j.m.p.MavenWebAppContext@2e1b374c{/bk,[file:///home/Downloads/demo/src/main/webapp/],AVAILABLE}{/home/Downloads/demo/target/demo-0.0.1-SNAPSHOT.war}
[INFO] Started ServerConnector@4eeab3e{HTTP/1.1, (http/1.1)}{0.0.0.0:8081}
[INFO] Started Server@161dd92a{STARTING}[11.0.21,sto=0] @2069ms
[INFO] Automatic redeployment disabled, see ‘mvn jetty:help’ for more redeployment options
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.8</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<url/>
<licenses>
<license/>
</licenses>
<developers>
<developer/>
</developers>
<scm>
<connection/>
<developerConnection/>
<tag/>
<url/>
</scm>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
<exclusion>
<groupId>io.dropwizard.metrics</groupId>
<artifactId>metrics-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-hateoas</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.7.Final</version>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>myTest</id>
<activation>
</activation>
<properties>
<deployable.artifactId>${project.artifactId}</deployable.artifactId>
<ojdbc.scope>compile</ojdbc.scope>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>3.5.0</version>
<executions>
<execution>
<id>enforce-configuration-setup</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireFilesExist>
<files>
<file>${project.basedir}/src/main/resources</file>
</files>
</requireFilesExist>
</rules>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<!--<version>9.4.50.v20221201</version>-->
<version>11.0.21</version>
<configuration>
<testClassesDirectory>${project.basedir}/target/resources</testClassesDirectory>
<httpConnector><port>8081</port></httpConnector>
<contextXml>${project.build.directory}/jetty.xml</contextXml>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/webapp</directory>
<filtering>true</filtering>
<targetPath>${project.build.directory}</targetPath>
</resource>
<resource>
<directory>src/main/context</directory>
<filtering>true</filtering>
<targetPath>${project.build.directory}</targetPath>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<targetPath>${project.build.directory}/resources</targetPath>
</resource>
</resources>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>jks</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<archive>
<manifest>
<mainClass>com.example.demo.DemoApplication</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
Jetty.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/bk</Set>
<Set name="war">/home/Downloads/demo/target/demo-0.0.1-SNAPSHOT.war</Set>
<Set name="extraClasspath">/home/Downloads/demo/target/resources</Set>
</Configure>
I tried to start spring boot application by changing different jetty version compatible with JDK 17 also added web.xml to manually provide the listener class, but application initialization is not happening. I would like to initiate spring boot application by triggering jetty server.
<listener>
<listener-class>org.springframework.web.context.WebApplicationContext</listener-class>
</listener>
Debarshi Saha is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.