1

On my local server, I'm able to make my api calls to my server and I can see that the values are being saved into the database. But when going live and using the actual domain address, I'm getting the error below:

java.lang.NoClassDefFoundError: Could not initialize class d.d.util.HibernateUtil

My HibernateUtil.java is:

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


public class HibernateUtil {

    private static final SessionFactory sessionFactory = buildSessionFactory();



       private static SessionFactory buildSessionFactory() {
            try {
                // Create the SessionFactory from hibernate.cfg.xml
                return new Configuration().configure().buildSessionFactory();
            }
            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;
        }

        public static void shutdown() {
            // Close caches and connection pools
            getSessionFactory().close();
        }

    }

Logs from Amazon are showing me something else:

Exception occurred during processing request: uid is required
java.lang.Exception: uid is required
    at d.d.Pamper.action.GetUserProfileAction.execute(GetUserProfileAction.java:16) ~[classes/:?]

This is my own exception that I'm throwing if the UID comes in null.

Noman
  • 887
  • 1
  • 15
  • 34

2 Answers2

1

NoClassDefFoundError means HibernateUtil missing some dependent class. It seems like, you missing org.hibernate.* classes at your live system.

Zufar Muhamadeev
  • 3,085
  • 5
  • 23
  • 51
  • So how do I upload my dependencies? – Noman Feb 02 '18 at 11:43
  • There are a lot of options. For example package them with maven to single jar. I typicaly use spring boot maven plugin. What kind of application do you have, and how you deploy it? – Zufar Muhamadeev Feb 02 '18 at 12:06
  • Its a struts2 application, I'm using eclipse to export to as a war file and then uploading it to the Amazon's elastic beanstalk. – Noman Feb 02 '18 at 12:25
  • try using maven war plugin: here is simple example https://stackoverflow.com/questions/21173514/create-war-file-from-pom-xml-for-an-existing-maven-project – Zufar Muhamadeev Feb 02 '18 at 13:12
  • Thank you, I tried like this but I'm still getting the same error – Noman Feb 02 '18 at 21:00
  • i suggest you to check at your production environment is org.hibernate.SessionFactory and org.hibernate.cfg.Configuration classed contain in classpath. Consider to read this https://docs.oracle.com/javase/tutorial/essential/environment/paths.html if your don`t understand how classpath works in java. – Zufar Muhamadeev Feb 04 '18 at 13:02
0

I was using Amazon's database which needs some configuration in order to be accessible from the internet.

Noman
  • 887
  • 1
  • 15
  • 34