Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
exlipzSnx7
Post subject: Please help : Exception ClassNotFound  PostPosted: Sep 22, 2008 - 02:27 PM



Joined: Sep 17, 2008
Posts: 17

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

Code:

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 ...

Code:

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
 
 View user's profile Send private message  
Reply with quote Back to top
support-nipun
Post subject: RE: Please help : Exception ClassNotFound  PostPosted: Sep 22, 2008 - 05:36 PM
Registered Member
Registered Member


Joined: Apr 18, 2007
Posts: 5657

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 ?

_________________
Nipun
MyEclipse Support
 
 View user's profile Send private message Send e-mail  
Reply with quote Back to top
exlipzSnx7
Post subject: Re: RE: Please help : Exception ClassNotFound  PostPosted: Sep 23, 2008 - 07:50 AM



Joined: Sep 17, 2008
Posts: 17

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!!!
 
 View user's profile Send private message  
Reply with quote Back to top
exlipzSnx7
Post subject:   PostPosted: Sep 23, 2008 - 08:18 AM



Joined: Sep 17, 2008
Posts: 17

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

Code:

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
 
 View user's profile Send private message  
Reply with quote Back to top
Support-Brian
Post subject:   PostPosted: Sep 24, 2008 - 09:38 PM
Moderator
Moderator


Joined: Aug 21, 2004
Posts: 1294

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.

_________________
Brian
MyEclipse Support
 
 View user's profile Send private message Visit poster's website  
Reply with quote Back to top
exlipzSnx7
Post subject:   PostPosted: Sep 25, 2008 - 09:38 AM



Joined: Sep 17, 2008
Posts: 17

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...

Code:

<?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>
 
 View user's profile Send private message  
Reply with quote Back to top
exlipzSnx7
Post subject:   PostPosted: Sep 26, 2008 - 09:40 AM



Joined: Sep 17, 2008
Posts: 17

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...

Code:

<?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
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT - 6 Hours
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2004 The PNphpBB Group
Credits