facebook

Please help : Exception ClassNotFound

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #289236 Reply

    exlipzSnx7
    Member

    Hi, am using MyEclipse. The tutorial is on Hibernate & Spring …

    
    Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
        at org.springframework.beans.factory.support.AbstractBeanFactory.<init>(AbstractBeanFactory.java:94)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:109)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.<init>(AbstractAutowireCapableBeanFactory.java:118)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.<init>(DefaultListableBeanFactory.java:87)
        at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:72)
        at org.springframework.beans.factory.xml.XmlBeanFactory.<init>(XmlBeanFactory.java:61)
        at com.myeclipse.hibernatespring.BusinessLogic.main(BusinessLogic.java:23)
    

    I do have the commons-loggin.jar added to the Java Build Path …

    My class …

    
    package com.myeclipse.hibernatespring;
    
    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.beans.factory.xml.XmlBeanFactory;
    import org.springframework.core.io.ClassPathResource;
    
    public class BusinessLogic 
    {
        public static void main(String[] args) 
        {
            /* 1. Create new user  */
            Integer id = new Integer(1);
            User user = new User();
            
            user.setUserId(id);
            user.setUsername("snx20");
            user.setPassword("102077");
            user.setFirstName("Sonx");
            user.setLastName("Nkukwi");
            user.setDateCreated(Integer.valueOf((int) System.currentTimeMillis()));    
        
            /* 2. Load the Spring bean configuration and create a bean factory */
            BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource ("applicationContext.xml"));
            
            /* 3. Create instance of PersistanceLayer */
            PersistenceLayer persistenceLayer = (PersistenceLayer) beanFactory.getBean("persistenceLayer");
            
            /* 4. Save the new user to the database */
            persistenceLayer.addUser(user);
            
            /* 5. Confirm that your user was added */ 
             User userLoadedFromDB = persistenceLayer.findUserById(id);
             
             System.out.print("User Loaded from DB [username="
                         + userLoadedFromDB.getUsername() + ", password="
                         + userLoadedFromDB.getPassword() + ", firstName="
                         + userLoadedFromDB.getFirstName() + ", lastName="
                         + userLoadedFromDB.getLastName() + "]");     
             
             /* 6. Update the user */
             userLoadedFromDB.setFirstName("Lungile");
             persistenceLayer.updateUser(userLoadedFromDB);
             
             /* Confirm that the update worked */
             User userLoadedFromDBAgain = persistenceLayer.findUserById(id);
             System.out.print("User Loaded from DB Again [fistName="
                         + userLoadedFromDBAgain.getFirstName() + "]");
        
             /* 8. Delete the user */
            persistenceLayer.deleteUser(user); 
        }
    }
    

    What is MyEclipse classpath anyway? is it the Build path

    #289251 Reply

    Loyal Water
    Member

    If you have the jar added to your project build path then you should not get this error. Import the classes using the import statement at the top of your BusinessLogic. Do the classes show in the dropdown ?

    #289273 Reply

    exlipzSnx7
    Member

    @support-nipun wrote:

    If you have the jar added to your project build path then you should not get this error. Import the classes using the import statement at the top of your BusinessLogic. Do the classes show in the dropdown ?

    When i import it [org.apache.commons.logging.logFactory] , its underlined yellow [warning] and says is never used …

    The error may have to do with BeanFactory class i’m using which is imported from [org.springframework.beans.factory.BeanFactory] … I have tried the next for the whol of last week, i can’t seem to get the solution to this!!!

    #289274 Reply

    exlipzSnx7
    Member

    This [http://www.myeclipseide.com/documentation/quickstarts/hibernateandspring/] is the tutorial i’m using and something is not making sense here

    
    package com.myeclipse.hibernatespring;
    
    public class BusinessLogic {
        public static void main(String[] args) {
            /* 1. Create a new user */
            Integer id = new Integer(1);
            User user = new User();
            user.setId(id);
            user.setUsername("jdoe");
            user.setPassword("1234");
            user.setFirstName("John");
            user.setLastName("Doe");
            user.setDateCreated(Long.valueOf(System.currentTimeMillis()));
    
            /* 2. Load the Spring bean configuration and create a bean factory */
            BeanFactory beanFactory = new XmlBeanFactory(new ClassPathResource(
                    "applicationContext.xml"));
    
            /* 3. Create instance of PersistenceLayer */
            PersistenceLayer persistenceLayer = (PersistenceLayer) beanFactory
                    .getBean("persistenceLayer");
    
            /* 4. Save the new user to the database */
            persistenceLayer.addUser(user);
    
            /* 5. Confirm that our user was saved */
            User userLoadedFromDB = persistenceLayer.findUserById(id);
            System.out.println("User Loaded from DB [username="
                    + userLoadedFromDB.getUsername() + ", password="
                    + userLoadedFromDB.getPassword() + ", firstName="
                    + userLoadedFromDB.getFirstName() + ", lastName="
                    + userLoadedFromDB.getLastName() + "]");
    
            /* 6. Update the user */
            userLoadedFromDB.setFirstName("Johnathan");
            persistenceLayer.updateUser(userLoadedFromDB);
    
            /* 7. Confirm that the update worked */
            User userLoadedFromDBAgain = persistenceLayer
                    .findUserById(id);
            System.out.println("User Loaded from DB Again [firstName="
                    + userLoadedFromDBAgain.getFirstName() + "]");
    
            /* 8. Delete the user */
            persistenceLayer.deleteUser(user);
        }
    } 
    

    This class does not import anything … If i copy and paste it i get errors BeanFactory cannot be resolve, which is the reason i imported the suggested classes… This tut as i said before is not very clear at some points

    #289336 Reply

    Brian Fernandes
    Moderator

    Could you please paste the contents of the .classpath file in your project here? The .classpath file is in the root of your project, it may be filtered in the Package Explorer so you can either unhide it or access the file from windows explorer.

    #289358 Reply

    exlipzSnx7
    Member

    @Support-Brian wrote:

    Could you please paste the contents of the .classpath file in your project here? The .classpath file is in the root of your project, it may be filtered in the Package Explorer so you can either unhide it or access the file from windows explorer.

    here…

    
    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.hibernate.MYECLIPSE_HIBERNATE3_2_EM"/>
        <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.hibernate.MYECLIPSE_HIBERNATE3_2_CORE"/>
        <classpathentry kind="lib" path="lib/mysql-connector-java-5.1.6-bin.jar"/>
        <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING25_CORE"/>
        <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Springframework-2.5-User"/>
        <classpathentry kind="lib" path="C:/Spring-framework-2.5.5/lib/hibernate/commons-logging-1.1.1.jar"/>
        <classpathentry kind="output" path="bin"/>
    </classpath>
    
    #289406 Reply

    exlipzSnx7
    Member

    @exlipzSnx7 wrote:

    @Support-Brian wrote:

    Could you please paste the contents of the .classpath file in your project here? The .classpath file is in the root of your project, it may be filtered in the Package Explorer so you can either unhide it or access the file from windows explorer.

    here…

    
    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
        <classpathentry kind="src" path="src"/>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
        <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.hibernate.MYECLIPSE_HIBERNATE3_2_EM"/>
        <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.hibernate.MYECLIPSE_HIBERNATE3_2_CORE"/>
        <classpathentry kind="lib" path="lib/mysql-connector-java-5.1.6-bin.jar"/>
        <classpathentry kind="con" path="melibrary.com.genuitec.eclipse.springframework.MYECLIPSE_SPRING25_CORE"/>
        <classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Springframework-2.5-User"/>
        <classpathentry kind="lib" path="C:/Spring-framework-2.5.5/lib/hibernate/commons-logging-1.1.1.jar"/>
        <classpathentry kind="output" path="bin"/>
    </classpath>
    

    Who’s the author of this tutorial, can i email him/her or something … I really need this solved. I’m not getting help anywhere

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: Please help : Exception ClassNotFound

You must be logged in to post in the forum log in