5
respostas

Problemas com import

Criei o projeto web no maven e estou tendo problemas com os imports

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.759 s
[INFO] Finished at: 2019-04-28T20:02:45-03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.0:compile (default-compile) on project gerenciador: Compilation failure: Compilation failure: 
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/NovaEmpresaServlet.java:[6,21] package javax.servlet does not exist
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/NovaEmpresaServlet.java:[7,32] package javax.servlet.annotation does not exist
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/NovaEmpresaServlet.java:[8,26] package javax.servlet.http does not exist
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/NovaEmpresaServlet.java:[9,26] package javax.servlet.http does not exist
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/NovaEmpresaServlet.java:[10,26] package javax.servlet.http does not exist
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/NovaEmpresaServlet.java:[17,41] cannot find symbol
[ERROR]   symbol: class HttpServlet
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/NovaEmpresaServlet.java:[16,2] cannot find symbol
[ERROR]   symbol: class WebServlet
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/NovaEmpresaServlet.java:[22,31] cannot find symbol
[ERROR]   symbol:   class HttpServletRequest
[ERROR]   location: class br.com.gerenciador.servlet.NovaEmpresaServlet
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/NovaEmpresaServlet.java:[22,59] cannot find symbol
[ERROR]   symbol:   class HttpServletResponse
[ERROR]   location: class br.com.gerenciador.servlet.NovaEmpresaServlet
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/NovaEmpresaServlet.java:[22,96] cannot find symbol
[ERROR]   symbol:   class ServletException
[ERROR]   location: class br.com.gerenciador.servlet.NovaEmpresaServlet
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/OiMundoServlet.java:[6,32] package javax.servlet.annotation does not exist
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/OiMundoServlet.java:[7,26] package javax.servlet.http does not exist
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/OiMundoServlet.java:[8,26] package javax.servlet.http does not exist
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/OiMundoServlet.java:[9,26] package javax.servlet.http does not exist
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/OiMundoServlet.java:[13,37] cannot find symbol
[ERROR]   symbol: class HttpServlet
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/OiMundoServlet.java:[12,2] cannot find symbol
[ERROR]   symbol: class WebServlet
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/OiMundoServlet.java:[21,32] cannot find symbol
[ERROR]   symbol:   class HttpServletRequest
[ERROR]   location: class br.com.gerenciador.servlet.OiMundoServlet
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/OiMundoServlet.java:[21,56] cannot find symbol
[ERROR]   symbol:   class HttpServletResponse
[ERROR]   location: class br.com.gerenciador.servlet.OiMundoServlet
[ERROR] /C:/Users/Alex/Documents/Alura/Servlets/gerenciador/src/main/java/br/com/gerenciador/servlet/OiMundoServlet.java:[20,9] method does not override or implement a method from a supertype
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

Porém na classe não mostra nenhum erro de import.

5 respostas

Classe sem erro algum:

package br.com.gerenciador.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.gerenciador.dao.EmpresaDAO;
import br.com.gerenciador.modelo.Empresa;


@WebServlet("/novaEmpresa")
public class NovaEmpresaServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;


    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("Cadastrando uma nova empresa");

        Empresa empresa = new Empresa();
        empresa.setNome(request.getParameter("nome"));

        EmpresaDAO dao = new EmpresaDAO();
        dao.inserir(empresa);

        PrintWriter out = response.getWriter();
        out.print("<html><body>Empresa " + empresa.getNome() + " cadastrada com sucesso!</body></html>");

    }

}

Olá José!

Quando você tenta executar o comando do Maven pelo terminal ele gera o mesmo erro?

Ele diz que eu tô referenciando o JRE em vez do JDK.

Você está utilizando Windows, certo?

Tenta desinstalar o Java no painel de controle e instala a JDK.

https://www.oracle.com/technetwork/pt/java/javase/downloads/jdk8-downloads-2133151.html

Depois reinicia a IDE, geralmente ela procura pelo caminho do JDK e por isso reinstalar pode fazer funcionar.

Mas caso não funcione me avisa por aqui que vou atrás de outra solução.

Olá José!

Conseguiu resolver o problema?

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software