Servlet cannot be resolved in web.xml - java

For some reason idea lights dispatcher servlet and when I launch tomcat get the 404 error. I`m using spring mvc and Maven, here is the picture of web.xml
Appreciate every answer=)
webapp/web.xml
<web-app 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_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>

Found the problem, was using the tomcat7-maven-plugin with compile version of maven-compiler-plugin 1.8, after changing it to 1.7 the problem gone.
However is there any similar solutions to tomcat7-maven-plugin?, cause I didnt find tomcat8-maven-plugin in internet
Thanks everyone for participation

Open settings below:
Project settings -> Facets -> Web -> Deployment Descriptors
check the path here and ensure it's available. If not, click the green + to add your web module path.

You need to add servlet mapping also and then add spring-webmvc-version.jar in classpath
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

I was having this same problem. It turned out that I was using an old companies settings.xml file for Maven user settings file. If someone is having this problem try using the Maven template users file.

Add spring mvc.jar file (if you are using spring and mvc) to the class libraries
Make sure that [name]-sevlet.xml file is set properly.
use name inside the "sevlet-name" name "servlet-name" in the web.xml.

I add the path for Web module. Using Intellij click project structure and then select Facets. Deployment Descriptors probably must be empty(its not good), so add the path.

Related

ClassNotFoundException on ServletContainer when configuring Jersey in Intellij

When trying to configure jax rs in intellij I get this error:
java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1945)
My webconfig looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>Rest</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.umbrella.server.api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Rest</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
</web-app>
I manually downloaded the entire jersey pack from the official jersey website. Which should contain all the dependencies.
The weird thing is that whenever I create a class that derives from the ServletContainer it doesn't give any errors.
I found the anwser with the help of Eugen Covaci.
In the Intellij project settings there is a tab called problems. When clicking solve on the problems listed there it started working again.
Another issue was that the jar files were located in web/WEB_INF/libs/api instead of the correct folder (web/WEB_INF/lib)

web.xml and pom.xml documentation

I need documentation about web.xml and pom.xml files. i would like learn web develop, so i start some tutorials about that. I use IDE eclipse and i choose the option maven project for develop the tutorials. i dont have errors but i cant deploy the projects in web. May be my problems are that i not understand in totality the concept of this files. Some documentation about this i sure that help me. I searched in Satck, in foros but i dont found documentation. I wonder how web developers know the code they need these files
web.xml is web application configuration file defines the servlet container used in the application. You can typically add start-up code, url-pattern as this will be called on application start. Example below extracted from Jersey RestFull service.
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.xxxx.shopper</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>com.xxxx.shopper.service.Startup</listener-class>
</listener>
</web-app>
pom.xml is maven configuration file defines build process and loads any dependencies.
Good Reads:
1. https://www.mkyong.com/maven/how-to-create-a-web-application-project-with-maven/
2. Difference between web projects with pom.xml and web.xml
3. Why do we use web.xml?

Jersey Services with Tomcat and Eclipse

I'm developing a rest service with Jersey 2.0 (I downloaded from http://repo1.maven.org/maven2/org/glassfish/jersey/bundles/jaxrs-ri/2.5/jaxrs-ri-2.5.zip) and I'm using Tomcat 7.0.47. I run Tomcat from Eclipse and my machine is a Mac.
I'm using the Eclipse tool to generate a WAR and to deploy the service.
This is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>MyServices</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.service.services.Services</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
</web-app>
I include all Jersey jars into WEB-INF/lib, except javax.servlet-api-3.0.1.jar that it is into Apache/lib
When I deploy in Tomcat, it shows a very strange error caused by:
Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.ClientConfig
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
... 70 more
My solution:
Add into Tomcat/lib all libraries that you download from Jersey and
are including into /ext folder of the Jersey .zip
Add into Web-Inf/lib of my project only libraries that are under /lib folder of the Jersey zip file
Add into Web-Inf/lib of my project javax.ws.rs-api-2.jar that you can find in /api folder of Jersey
With this, I don't have problems to run Tomcat with Jersey.
And this is my web.xml for Jersey 2.0
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>MyRESTServices</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.myservice.services</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
Where com.myservice.services is the package where I have my services
Thanks for your comments!!
It works for me on a PC. Did you make the eclipse project a maven project? If you do that then you can use org.glassfish.jersey.bundles jaxrs-ri version 2.5 (or whichever) as a dependency in your pom and then when you do run->maven-install from eclipse it will build a war file with all the necessary dependencies in it.
Adding Jersey to an Eclipse project without maven is simple: Click properties for the project, go to the Java Build Path. Click on the Add Library on the left, select user library. After you click next you will see "user libraries" in the upper right. Click that. Click new. Add a name: jaxrs-ri-2.5 for example. Click add external jars, and add the jars in the api, lib and ext folders. You're done. This will probably also include them in any war file you make with eclipse.
Worked for me.
Go with jdk1.7.0_04 and install apache-tomcat-7.0.55 and set the environment variable for this setting and set eclipse for same for compiling building and runtime. then everything will be OK for Jax-RS-2.1

Problems with JSF Using GlassFish

[In case it is helpful, I am working from the book Core JavaServer Faces (3rd edition) and am on page 12, or thereabouts.]
I am trying to launch a JSF application using GlassFish but am having problems that I can't identify. I can start GlassFish correctly and see the screen that is depicted in the book, so that appears to be fine. I then copy the file login.war that I've created and placed in the directory containing the src and web directories for this project into the domains/domain1/autodeploy directory of GlassFish.
Going to http://localhost:8080 in Chrome shows the correct screen; however http://localhost:8080/login, as described in the book and corresponding to the login.xhtml page that I have created, simply returns an HTTP 404 Error telling me 'The requested resource () is not available'.
My web.xml file is as follows:
<?xml version="1.0" encoding="UTf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/nx/javaee
http://java.sun.com/xml/ns/javaee/we-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-patter>/faces/*</url-patter>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
</web-app>
Can anyone offer any help? I am using the Eclipse IDE, my version of GlassFish, as detailed on the error page described above, is 3.1.2.2. If there is any more information that would be helpful, e.g. directory structures, please do ask me for it.
Thanks, Conor.
You should set your application context-root to login if you need to access it with http://localhost:8080/login. There are several ways how to do it, e.g. check this Glassfish tip or in Eclipse IDE, in project Properties click on Web Project Settings and enter new Context root of your application.
This is not a bug, so until you will run more then one application on your server, you can leave it this way if you wish.

How to disable SystemServiceServlet configuration in App Engine project?

The Google Plugin for Eclipse auto-generates these lines in web.xml no matter what the project properties are set to:
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value/>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
Is there a way to prevent the plugin to do that?
In your project Properties, under Builders, if you disable Google App Engine Project Change Notifier, your web.xml won't by modified anymore.
However, not been keen enough to the GAE environment, I can't tell which are the side-effects of disabling this builder.
Remove the above xml from web.xml and add readonly attribute to web

Categories