Announcement Announcement Module
Collapse
No announcement yet.
ClassPathXmlApplicationContext problem !! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ClassPathXmlApplicationContext problem !!

    Please help !!!!!

    I have a very simple standalone Java console app helloWorld with Spring.
    it wirks when I create BeanFactory but does not when I create ApplicationContext
    why?
    if I uncomment first 2 lines and comment the third it works, otherwise I get the expetion I will attach, I also attach applicationContext.xml fiel that resides in my root directory and placed on the CLASSPATH

    ----------------------------

    import org.springframework.beans.factory.BeanFactory;
    import org.springframework.beans.factory.xml.XmlBeanFacto ry;
    import org.springframework.context.ApplicationContext;


    import org.springframework.context.support.ClassPathXmlAp plicationContext;
    import org.springframework.core.io.ClassPathResource;
    import org.springframework.core.io.FileSystemResource;
    import org.springframework.core.io.Resource;

    public class Hello {

    /**
    * @param args
    */
    public static void main(String[] args) {


    //1 ClassPathResource resource = new ClassPathResource("applicationContext.xml");
    //2 BeanFactory factory = new XmlBeanFactory(resource);
    ApplicationContext beanFactory = new ClassPathXmlApplicationContext(new String("applicationContext.xml"));
    }
    }
    ------------------------------
    applicationContext.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
    <beans>
    <bean id="story" class="Story">
    <property name="title">
    <value>Never ending story</value>
    </property>
    </bean>


    </beans>

    ---exception:

    25-Dec-2008 12:24:39 org.springframework.context.support.AbstractApplic ationContext prepareRefresh
    INFO: Refreshing org.springframework.context.support.ClassPathXmlAp plicationContext@54172f: display name [org.springframework.context.support.ClassPathXmlAp plicationContext@54172f]; startup date [Thu Dec 25 12:24:39 GMT 2008]; root of context hierarchy
    25-Dec-2008 12:24:39 org.springframework.beans.factory.xml.XmlBeanDefin itionReader loadBeanDefinitions
    INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
    25-Dec-2008 12:24:39 org.springframework.context.support.AbstractApplic ationContext obtainFreshBeanFactory
    INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlAp plicationContext@54172f]: org.springframework.beans.factory.support.DefaultL istableBeanFactory@16a9d42
    Exception in thread "main" java.lang.NoClassDefFoundError: org/antlr/runtime/Lexer
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    at org.springframework.context.expression.StandardBea nExpressionResolver.<init>(StandardBeanExpressionR esolver.java:40)
    at org.springframework.context.support.AbstractApplic ationContext.prepareBeanFactory(AbstractApplicatio nContext.java:442)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:353)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:139)
    at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationCon text.java:83)
    at Hello.main(Hello.java:22)
    Caused by: java.lang.ClassNotFoundException: org.antlr.runtime.Lexer
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClassInternal(Unknown Source)
    ... 18 more

  • #2
    I have this problem like u.

    look at this
    i use netbeans and i didnt see any exception!!!.

    Comment


    • #3
      add jar file

      hi,

      Add antlr.jar to spring Lib ,check it.

      Comment


      • #4
        About antlr.jar

        Hi, Akumar1
        Please give more information about antlr.jar and how it works and why it is usefull for this problem .
        tnx.

        Comment


        • #5
          Areff,
          This is used for language recongition; it has been used to build a tool to translate java into C and it has been used to translate the Hibernate Query langauge into SQL language in Hibernate; you can find more information at http://www.antlr.org
          You can dowload it from www.antlr.org

          Comment


          • #6
            Tnx Alan,
            but why this is usefull for our problem .
            look at this thread about my problem.

            Comment


            • #7
              Re..

              hi,




              Exception in thread "main" java.lang.NoClassDefFoundError: org/antlr/runtime/Lexer,so the grammar of your applicationContext.xml file may not recognized because the class def not found,so just add antlr.jar file and check,

              regards,

              Comment


              • #8
                I believe you need the antlr-runtime jar, not the antlr.jar

                Hope it helps

                Comment


                • #9
                  You can download at You can download from http://www.findjar.com/jar/org.antlr...e-3.0.jar.html

                  Comment


                  • #10
                    thank

                    Guys it worked, with run time jar. thanks alot

                    Comment

                    Working...
                    X