Error deploying a Maven project

Asked

Viewed 121 times

0

This is my first complete project with Maven, when I spin in the IDE works perfectly but when I do deploy on the server Tomcat some mistakes happen.

Error that happens when I try to enter the system from the Server of the company in which it is installed Tomcat.

   Login.xhtml: Property 'entrar' not found on type com.tarefamanager.bean.UsuarioBean

When I deploy it in my machine and try to get in it happens:

java.lang.NoClassDefFoundError: Could not initialize class com.tarefamanager.util.HibernateUtil

Only the IDE works. Has anyone gone through it? Can anyone help?


Hibernateutil:

public class HibernateUtil {

private static final SessionFactory sessionFactory = buildSessionFactory();

private static SessionFactory buildSessionFactory() {
    try {
        // Create the SessionFactory from hibernate.cfg.xml
        Configuration configuration = new Configuration();
        configuration.configure();

        ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                .applySettings(configuration.getProperties()).build();

        SessionFactory sessionFactory = configuration.buildSessionFactory(serviceRegistry);
        return sessionFactory;

    } catch (Throwable ex) {
        // Make sure you log the exception, as it might be swallowed
        System.err.println("Initial SessionFactory creation failed." + ex);
        throw new ExceptionInInitializerError(ex);
    }
}

public static SessionFactory getSessionFactory() {
    return sessionFactory;
}

}

User:

@ManagedBean(name = "usuarioBean")
@SessionScoped
public class UsuarioBean {
    private Usuario usuarioLogado;
    private Usuario usuario;
    public static final long TEMPO = (1000 * 60 * 1);

    public Usuario getUsuarioLogado() {
        if (usuarioLogado == null) {
            usuarioLogado = new Usuario();
        }
        return usuarioLogado;
    }

    public void setUsuarioLogado(Usuario usuarioLogado) {
        this.usuarioLogado = usuarioLogado;
    }

    public Usuario getUsuario() {
        if (usuario == null) {
            usuario = new Usuario();
        }
        return usuario;
    }

    public void setUsuario(Usuario usuario) {
        this.usuario = usuario;
    }

    public void salvar() {
        try {
            UsuarioDAO usuarioDAO = new UsuarioDAO();
            usuarioDAO.salvar(usuario);

            FacesUtil.adicionarMsgInfo("Usuario Salvo com Sucesso");
            usuario = new Usuario();
        } catch (RuntimeException e) {
            FacesUtil.adicionarMsgErro("Erro ao Salvar Usuario");
            e.printStackTrace();
        }
    }

    public void limpar() {
        usuario = new Usuario();
    }

    public String entrar() {
        try {
            UsuarioDAO usuarioDAO = new UsuarioDAO();
            usuarioLogado = usuarioDAO.autenticar(usuarioLogado.getLogin(),
                    usuarioLogado.getSenha());

            if (usuarioLogado == null) {
                FacesUtil.adicionarMsgErro("Login ou Senha inválidos");
                return "";
            } else {
                FacesUtil
                        .adicionarMsgInfo("Funcionário Autenticado com Sucesso");
                return "Home.xhtml?faces-redirect=true";
            }
        } catch (RuntimeException ex) {
            FacesUtil.adicionarMsgErro("Erro ao entrar no sistema "
                    + ex.getMessage());
        }
        return "";
    }

    public void out() throws IOException {
        // ...
        ExternalContext ec = FacesContext.getCurrentInstance()
                .getExternalContext();
        ec.redirect(ec.getRequestContextPath() + "/Login.xhtml");
    }

    public String sair() {
        usuarioLogado = null;
        return "/Login.xhtml?faces-redirect=true";
    }

    @PostConstruct
    private void executarTarefa() {
        // ****INICIA A TAREFA ELE VERIFICA A CADA UM MINUTO****//
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy hh:mm");
        System.out.println("Iniciado!");

        Timer timer = null;
        if (timer == null) {
            timer = new Timer();
            TimerTask tarefa = new TimerTask() {
                @Override
                public void run() {
                    try {

                        System.out.println("Arquivo Gerado");
                        System.out.println(sdf.format(new Date()));
                        List<Tarefa>lista = atualizarInicial();
                        System.out.println(lista);

                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            };
            timer.scheduleAtFixedRate(tarefa, TEMPO, TEMPO);
        }

    }

    public List<Tarefa> atualizarInicial() {

        Session sessao = HibernateUtil.getSessionFactory().openSession();
        Transaction transacao = sessao.beginTransaction();

        List<Tarefa> lista = new ArrayList<>();
        try {
            Query consulta = sessao.getNamedQuery("Tarefa.listarPorCodigo");
            consulta.setParameter("usuario", usuario);
            lista = consulta.list();
            System.err.println("LISTA no DAO: " + lista);
            transacao.commit();
        } catch (RuntimeException ex) {
            throw ex;
        } finally {
            sessao.close();
        }
        return lista;
    }
}
  • You can put the code of the two classes ?

  • I can, I’ll edit the question.

  • 1

    Have you built the project again? If you’re using Eclipse Go to Run -> Run Configurations -> Two clicks in Maven Build. Select your project and under "Goals" put clean Compile install. You can also right-click the project -> Maven -> update project. When that happens here, I do one of the two and it solves.

  • Oops, I did that and it worked kk. Puts an answer for me to mark as solution

1 answer

0


Already built the project again?

If you’re using Eclipse Go to Run -> Run Configurations -> Two clicks in Maven Build. Select your project and in "Goals" put clean Compile install.

You can also right-click the project -> Maven -> Update project. When this happens here, I do one of the two and resolve.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.