-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Difficulty working with Ant...
PostPosted: Mon Feb 28, 2011 6:08 am 
Newbie

Joined: Mon Feb 28, 2011 5:52 am
Posts: 2
Hi,

I'm new to Hibernate and I'm following APress' "Beginning Hibernate 2nd Ed" by Jeff Linwood and Dave Minter. I'm having trouble getting the examples running using Ant as described in the book.

Code:
<project name="sample">

    <property file="build.properties"/>
    <property name="src" location="src"/>
    <property name="bin" location="bin"/>
    <property name="sql" location="sql"/>

    <path id="classpath.base">
        <pathelement location="${src}"/>
        <pathelement location="${bin}"/>
        <pathelement location="${hibernate.home}/hibernate3.jar"/>
        <pathelement location="${slf4j.implementation.jar}"/>
        <fileset dir="${hibernate.home}/lib" includes="**/*.jar"/>
        <pathelement location="${hsql.home}/lib/hsqldb.jar"/>
    </path>

    <path id="classpath.tools">
        <path refid="classpath.base"/>
        <pathelement location="${hibernate.tools}/commons-logging-1.0.4.jar"/>
        <pathelement location="${hibernate.tools}/freemarker.jar"/>
        <pathelement location="${hibernate.tools}/hibernate-tools.jar"/>
    </path>

    <taskdef name="htools"
             classname="org.hibernate.tool.ant.HibernateToolTask"
             classpathref="classpath.tools"/>

    <target name="exportDDL" depends="compile">
        <mkdir dir="${sql}"/>
        <htools destdir="${sql}">
            <classpath refid="classpath.tools"/>
            <annotationconfiguration configurationfile="${src}/hibernate.cfg.xml"/>
            <hbm2ddl>
                <property key="drop" value="true"/>
                <property key="outputFileName" value="sample.sql"/>
            </hbm2ddl>
        </htools>
    </target>

    <target name="compile">
        <javac srcdir="${src}" destdir="${bin}" classpathref="classpath.base"/>
    </target>

    <target name="populateMessages" depends="compile">
        <java classname="sample.PopulateMessages" classpathref="classpath.base"/>
    </target>

    <target name="listMessages" depends="compile">
        <java classname="sample.ListMessages" classpathref="classpath.base"/>
    </target>

</project>


The 'exportDDL' target works fine however when I execute 'populateMessages' and 'listMessages' I get the following error :

Code:
203 [main] INFO org.hibernate.annotations.common.Version - Hibernate Commons Annotations 3.2.0.Final
219 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.6.1.Final
219 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
219 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
235 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
344 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
344 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
Warning: Caught exception attempting to use SAX to load a SAX XMLReader
Warning: Exception was: java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
Warning: I will print the stack trace then carry on using the default SAX parser
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
   at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:189)
   at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:150)
   at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:83)
   at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894)
   at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715)
   at org.dom4j.io.SAXReader.read(SAXReader.java:435)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2208)
   at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:229)
   at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:70)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:2128)
   at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:211)
   at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:70)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:2107)
   at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:205)
   at sample.PopulateMessages.main(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
   at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
   at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
   at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
   at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
   at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
   at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
   at org.apache.tools.ant.Task.perform(Task.java:348)
   at org.apache.tools.ant.Target.execute(Target.java:357)
   at org.apache.tools.ant.Target.performTasks(Target.java:385)
   at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
   at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
   at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
   at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
   at org.apache.tools.ant.Main.runBuild(Main.java:758)
   at org.apache.tools.ant.Main.startAnt(Main.java:217)
   at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
   at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:32)
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser
   at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1400)
   at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1341)
   at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:1094)
   at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
   at org.xml.sax.helpers.NewInstance.newInstance(NewInstance.java:49)
   at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:187)
   ... 46 more
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
   at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:194)
   at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
   at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
   at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
   at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
   at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
   at org.apache.tools.ant.Task.perform(Task.java:348)
   at org.apache.tools.ant.Target.execute(Target.java:357)
   at org.apache.tools.ant.Target.performTasks(Target.java:385)
   at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
   at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
   at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
   at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
   at org.apache.tools.ant.Main.runBuild(Main.java:758)
   at org.apache.tools.ant.Main.startAnt(Main.java:217)
   at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
   at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:32)
Caused by: org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2216)
   at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:229)
   at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:70)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:2128)
   at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:211)
   at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:70)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:2107)
   at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:205)
   at sample.PopulateMessages.main(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
   at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
   ... 26 more
Caused by: org.dom4j.DocumentException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found Nested exception: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
   at org.dom4j.io.SAXReader.read(SAXReader.java:484)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2208)
   ... 40 more
--- Nested Exception ---
org.hibernate.HibernateException: Could not parse configuration: /hibernate.cfg.xml
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2216)
   at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:229)
   at org.hibernate.cfg.AnnotationConfiguration.doConfigure(AnnotationConfiguration.java:70)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:2128)
   at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:211)
   at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:70)
   at org.hibernate.cfg.Configuration.configure(Configuration.java:2107)
   at org.hibernate.cfg.AnnotationConfiguration.configure(AnnotationConfiguration.java:205)
   at sample.PopulateMessages.main(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
   at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
   at org.apache.tools.ant.taskdefs.Java.run(Java.java:764)
   at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:218)
   at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:132)
   at org.apache.tools.ant.taskdefs.Java.execute(Java.java:105)
   at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
   at org.apache.tools.ant.Task.perform(Task.java:348)
   at org.apache.tools.ant.Target.execute(Target.java:357)
   at org.apache.tools.ant.Target.performTasks(Target.java:385)
   at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1337)
   at org.apache.tools.ant.Project.executeTarget(Project.java:1306)
   at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
   at org.apache.tools.ant.Project.executeTargets(Project.java:1189)
   at org.apache.tools.ant.Main.runBuild(Main.java:758)
   at org.apache.tools.ant.Main.startAnt(Main.java:217)
   at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
   at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:597)
   at com.intellij.rt.ant.execution.AntMain2.main(AntMain2.java:32)
Caused by: org.dom4j.DocumentException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found Nested exception: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
   at org.dom4j.io.SAXReader.read(SAXReader.java:484)
   at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:2208)
   ... 40 more
Java Result: -1


However if I execute the two classes manually through my IDE they work fine.

Any idea what's going on?

Many Thanks in advance,

Anthony


Top
 Profile  
 
 Post subject: Re: Difficulty working with Ant...
PostPosted: Mon Feb 28, 2011 1:56 pm 
Newbie

Joined: Mon Feb 28, 2011 5:52 am
Posts: 2
Needless to say that the APress website is less than helpful...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.