Issue
I am writing a simple web service and have put my web.xml file in the WEB-INF folder. For some reason everything in the servlet-class tag is coming up as "cannot resolve class MyServlet". The class MyServlet is in the src folder under root directory. I cannot figure out why as to why this is happening.
<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_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/my/*</url-pattern>
</servlet-mapping>
Solution
I needed to mark my src folder as "Source Root" in IntelliJ. This can be done by right clicking the folder -> mark directory as. After that my class files actually became linkable.
Answered By - user3390527
Answer Checked By - Mary Flores (JavaFixing Volunteer)