Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Ant, Maven and Other Build Tools and the fly likes Ant build in Beginning Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "Ant build in Beginning Hibernate" Watch "Ant build in Beginning Hibernate" New topic
Author

Ant build in Beginning Hibernate

Emil Jennings
Ranch Hand

Joined: Jul 09, 2010
Posts: 48
I am extremely unfamiliar with Ant, so I copied the build.xml from the book:



And then made another file, build.properties:



I have the following files:
C:\dev\hibernate-distribution-3.6.0.Final\hibernate3.jar
C:\dev\slf4j-1.5.11\slf4j-simple-1.5.11.jar
C:\dev\hsqldb-2.0.1-rc2\hsqldb
C:\dev\eclipse\plugins\org.hibernate.eclipse_3.3.1.v201006011046R-H111-GA\lib\hibernate\commons-logging-1.0.4.jar
C:\dev\eclipse\plugins\org.hibernate.eclipse_3.3.1.v201006011046R-H111-GA\lib\tools\freemarker.jar
C:\dev\eclipse\plugins\org.hibernate.eclipse_3.3.1.v201006011046R-H111-GA\lib\tools\hibernate-tools.jar

And I have hibernate3.jar, freemarker.jar, and hibernate-tools.jar in the Referenced Libraries of my project. Can anyone tell me why I'm receiving the "taskdef class org.hibernate.tool.ant.HibernateToolTask cannot be found" error at line 27? From what the book says, I thought this was in the hibernate-tools.jar file or freemarker.jar file.

TIA.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

First, make sure that the class name is not a typo (is it "org.hibernate.tool...." or "org.hibernate.tools....").

Second, check the hibernate JARs you listed and make sure that one of them contains the HibernateToolTask.

Third, make sure that any classes that HibernateToolTask depends on are also in the tools.classpath.

Finally, if that all checks out, try running ant with the -v option - that will print out extract information that might give some clues.

(For items 2 and 3, see this post on tools to help locate classes: http://www.coderanch.com/t/536956/vc/HOWTO-Find-jar-file-which)


JBoss In Action
Emil Jennings
Ranch Hand

Joined: Jul 09, 2010
Posts: 48
Hi Peter,

For 1 - C:\dev\eclipse\plugins\org.hibernate.eclipse_3.3.1.v201006011046R-H111-GA\lib\tools\hibernate-tools.jar holds org.hibernate.tool.ant...no typo, check.

For 2 - The above jar has org.hibernate.tool.ant.HibernateToolTask.class, check.

For 3 - I don't know, I assume they are (I gave tattletale from your link a look, but it didn't make too much sense on the install / use part (I am brain fried at this point today).

For 4 - I used the -v option and received:


Is org.apache.tools.ant another jar I am unaware of?
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3827

From where you run the script?


In your xml you refer them as below: (I'm not sure how this is interpreted without a slash in between the two entries)

I suggest you use absolute paths in your "build.properties" file.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

Look very carefully at lines 7, 8 and 9 of the output. Do you see anything amiss with the file names given? You posted earlier that those files exist, and even posted the full path for those files. So why is Ant saying "it doesn't exist"?

Once you see the problem, fix line 7 in the build.xml. Or fix either line 2 or 3 in the build.properties file.

If that is not enough of a hint, let me know!
Emil Jennings
Ranch Hand

Joined: Jul 09, 2010
Posts: 48
Thanks Peter that was a good hint. With a little more tweaking of things the results of running the thing are:



According to the book, I'm assuming this is the expected results because it said I should see the script represented by lines 50 - 65, but I have to
admit I'm not sure what I've accomplished. Should I just continue to read and the answer will come?

Thanks again.
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5823
    
    7

Yes, continue reading the book. Hopefully the authors will explain what is going on. Usually, authors provide ant scripts to automatically build examples in the book. In some cases the authors list all of the code in the book itself and explain what all of the code does. Hopefully the authors of your book do the same. Unfortunately, I have seen too many cases where the authors only discuss a small fraction of a larger piece of code leaving you in the dark about the rest. Personally, I have never understood that. I prefer books that have small simple complete examples that I can type in by hand and compile/run, rather than long, involved examples that the author barely touches on. (I have also run into "getting started guides" where the entire "tutorial" consists of running an ant script. As if that explains how to build anything that works with the software!)
Emil Jennings
Ranch Hand

Joined: Jul 09, 2010
Posts: 48
Thanks Peter, I appreciate your help.
Emil Jennings
Ranch Hand

Joined: Jul 09, 2010
Posts: 48
A little more FYI for others experiencing this (since I am new with Ant and Hibernate this was a bit frustrating), the books examples were
developed for HSQLDB, so I had to modify the hibernate.cfg.xml to be MySQL compliant since that's what I'm using. After changing that,
I received the com.mysql.jdbc.Driver class not found exception. To make a long story short, the build.xml file had



which I changed to



And tried to run it all again for the gazillionth time. This time it was successful and the empty tables were created. The moral of the story for
all you newbies like me: make sure your hibernate.cfg.xml, build.xml, and build.properties files are all compliant for the database being used.
I hope this shortens the error solving time for others.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ant build in Beginning Hibernate