Problem in file OiMundoServlet.java - #algaworks

0

I'm following the E-book "Java EE7 with JSF, PrimeFaces and CDI". I created the Maven project, I edited the file pom.xml as the handbook guides, when I created the OiMundoServlet.java sample file, I noticed that errors appeared in the handbook, but when editing the file pom.xml again to eliminate the errors, those same mistakes are not gone. How to fix this?

  • Note 1: I am using the latest version of Eclipse Java EE (Mars.1 Release (4.5.1))
  • Note 2: When I added the apache 8 server, when linking the Maven project, I noticed the following error: Project facet Java version 1.8 is not supported .
  • Note 3: The web.xml file was not created automatically. I had to create it because it reported an error in the file pom.xml in the line referring to <packaging>war</packaging> .

Follow the code:

package br.com.farmsystem.servlet;//essa linha apresenta erro

import java.io.IOException;//essa linha apresenta erro
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class OiMundoServlet
 */
@WebServlet("/oi-mundo")
public class OiMundoServlet extends HttpServlet { //essa linha apresenta erro

    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public OiMundoServlet() {
        super();//essa linha apresenta erro
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//essa linha apresenta erro
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//essa linha apresenta erro
        // TODO Auto-generated method stub
    }

}
    
asked by anonymous 05.10.2015 / 23:32

3 answers

1

For the latest Java EE 7 platform, web.xml is no longer required, it is optional.

But for the sake of doubt, choosing to use as settings for other frameworks, you can use the latest version of servlet (3.1).

Servlet 3.1 - Descriptor

<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">
</web-app>

In Eclipse, when adding a new server in the New Server tab, if you choose Apache Tomcat 8 , click the Add button, in JRE choose Java version 8 in> but before you make sure that on your machine, you have the latest version of Java installed.

Alternatively,youcangotoPropertiesoftheproject,ProjectFacetsontheRuntimebuttonNewandchoosetheapplicationserver.

  

AlsomakesurethatProjectFacetsisthe1.8versionofJava.

Nopom.xmltospecifyJavaversion8,canbedonebymaven-compiler-plugin

<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.3</version><configuration><source>1.8</source><target>1.8</target></configuration></plugin></plugins></build>

AndtomakeexplicitforMaventhatweb.xmldoesnotneedtobecheckedordetected,itcanbedonethroughmaven-war-pluginsoitwillnotgenerateanyerrorsifitdoesnotexist.

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-war-plugin</artifactId><version>2.6</version><configuration><failOnMissingWebXml>false</failOnMissingWebXml></configuration></plugin>
  

Otherdescriptors-JavaEE7

link

    
10.01.2016 / 14:59
0

See if this helps you. Creating the WEB-INF folder and the web.xml file

    
15.04.2017 / 02:46
-1
  

error: Project facet Java version 1.8 is not supported.

What version of java do you use? to find out: on the terminal type java -version . Change pom.xml according to the version you use.

Eg: java -version -> 1.7.x

no pom.xml : replace references from java 1.8 to 1.7

    
10.01.2016 / 14:09