This is my first complete project with Maven
, when running in IDE it works perfectly however when I do deploy
on server Tomcat
some errors happen.
An error occurs when I try to enter the system through the Company Server on which Tomcat
is installed.
Login.xhtml: Property 'entrar' not found on type com.tarefamanager.bean.UsuarioBean
When I deploy my machine and try to log in, this happens:
java.lang.NoClassDefFoundError: Could not initialize class com.tarefamanager.util.HibernateUtil
Only in the IDE works. Has anyone ever experienced this? 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;
}
}
UserBean:
@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;
}
}