Answer the question
In order to leave comments, you need to log in
How to run Hello World on jetty-maven-plugin with web.xml config?
I tried various examples of launching and using the jetty-maven-plugin.
Some examples work, some don't.
The mapping example, via web.xml, doesn't work for some reason.
The server starts, but when you go to the page in the browser, the servlet returns 404 along the HelloWorldServlet
address
path . this request.
(When visiting localhost:8080/mySimpleApp/ - everything shows correctly, i.e. what is generated from index.jsp.)
(UPD: it turns out this is not quite an error, i.e. Jetty gives it, something like .. that nothing is specified for this address in the server settings.
)
It also gives an error javax.servlet.AsyncContext scanned from multiple locations - and this is strange because servlets need dependency: javax.servlet-api to work, but when you add it, this is the error when starting the server.
(UPD: changed to jetty-server dependency, and the javax.servlet.AsyncContext scanned from multiple locations error is gone.)
Project itself:
Project structure:
HelloWorldServlet.java
public class HelloWorldServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.getWriter().println("Hello World! From Servlet");
}
}
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<display-name>Archetype Created Web Application</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>basePkg.servlets.HelloWorldServlet</servlet-class>
</servlet>
<!-- привязываем его к адресу -->
<servlet-mapping>
<!-- при переходя по адресу /helloWorldServlet
Jetty - перенаправит запрос на сервлет HelloWorldServlet -->
<!-- в метод doGet(..) -->
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/helloWorldServlet</url-pattern>
</servlet-mapping>
</web-app>
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>simpleApp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>simpleApp Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
</dependencies>
<build>
<finalName>simpleApp</finalName>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.34.v20201102</version>
<configuration>
<jvmArgs>-Ddebug=true</jvmArgs>
<httpConnector>
<port>8080</port>
</httpConnector>
<webApp>
<contextPath>/mySimpleApp</contextPath>
</webApp>
</configuration>
</plugin>
</plugins>
</build>
</project>
Answer the question
In order to leave comments, you need to log in
Changed addiction
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>9.4.34.v20201102</version>
<scope>provided</scope>
</dependency>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question