Hi,
I am using some exporter to generate code like hbm2java,hbm2dao......
I extract hibernate-tools.jar and inside this I found daohome.ftl within dao folder.
In my project root directory I put CustomDAOTemplate.ftl(rename daohome.ftl) inside config folder.
but when I am using hbm2dao It says that file not found I,m really surprised.
In command prompt I found(ant hbm2dao results then ant -verbose) ::
Code:
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\Documents and Settings\ADMIN>cd\
C:\>cd junk
C:\junk>ant hbm2dao
Buildfile: build.xml
hbm2dao:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: generic exportertemplate: C:/junk/config/CustomDAOTempl
ate.ftl
[hibernatetool] 11:41:41,703 INFO Environment:520 - Hibernate 3.3.0.CR1
[hibernatetool] 11:41:41,718 INFO Environment:553 - hibernate.properties not fo
und
[hibernatetool] 11:41:41,718 INFO Environment:687 - Bytecode provider name : cg
lib
[hibernatetool] 11:41:41,734 INFO Environment:604 - using JDK 1.4 java.sql.Time
stamp handling
[hibernatetool] 11:41:41,812 INFO Configuration:1471 - configuring from file: h
ibernate.cfg.xml
[hibernatetool] 11:41:41,937 INFO Configuration:1552 - Configured SessionFactor
y: null
[hibernatetool] 11:41:42,281 INFO Configuration:309 - Reading mappings from fil
e: C:\junk\hibernate-src\events\Event.hbm.xml
[hibernatetool] 11:41:42,406 INFO HbmBinder:299 - Mapping class: events.Event -
> EVENTS
[hibernatetool] 11:41:42,437 INFO Configuration:309 - Reading mappings from fil
e: C:\junk\hibernate-src\events\Person.hbm.xml
[hibernatetool] 11:41:42,468 INFO HbmBinder:299 - Mapping class: events.Person
-> PERSON
[hibernatetool] 11:41:42,640 INFO Version:15 - Hibernate Tools 3.2.0.b9
[hibernatetool] An exception occurred while running exporter #2:generic exporter
template: C:/junk/config/CustomDAOTemplate.ftl
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.tool.hbm2x.ExporterException: Error while processi
ng template C:/junk/config/CustomDAOTemplate.ftl
[hibernatetool] java.io.FileNotFoundException: Template C:/junk/config/CustomDAO
Template.ftl not found.
BUILD FAILED
C:\junk\build.xml:142: org.hibernate.tool.hbm2x.ExporterException: Error while p
rocessing template C:/junk/config/CustomDAOTemplate.ftl
Total time: 3 seconds
C:\junk>ant -verbose
Apache Ant version 1.6.5 compiled on June 2 2005
Buildfile: build.xml
Detected Java version: 1.5 in: C:\jdk1.5.0_15\jre
Detected OS: Windows XP
parsing buildfile C:\junk\build.xml with URI = file:///C:/junk/build.xml
Project base dir set to: C:\junk
Build sequence for target(s) `createjar' is [clean, hbm2ddl, hbm2java, echo, hbm
2dao, hbm2hbmxml, hbm2doc, compile, createjar]
Complete build sequence is [clean, hbm2ddl, hbm2java, echo, hbm2dao, hbm2hbmxml,
hbm2doc, compile, createjar, ]
clean:
[delete] Deleting directory C:\junk\src
[delete] Deleting C:\junk\src\events\Event.java
[delete] Deleting C:\junk\src\events\Person.java
[delete] Deleting directory C:\junk\src\events
[delete] Deleting directory C:\junk\src
[delete] Deleting directory C:\junk\dao
[delete] Deleting directory C:\junk\dao
[delete] Deleting directory C:\junk\sql
[delete] Deleting C:\junk\sql\sql.ddl
[delete] Deleting directory C:\junk\sql
[delete] Deleting directory C:\junk\hbm
[delete] Deleting directory C:\junk\hbm
[delete] Deleting directory C:\junk\classes
[delete] Deleting directory C:\junk\classes
[delete] Deleting directory C:\junk\pub
[delete] Deleting directory C:\junk\pub
[mkdir] Created dir: C:\junk\src
[mkdir] Created dir: C:\junk\dao
[mkdir] Created dir: C:\junk\sql
[mkdir] Created dir: C:\junk\hbm
[mkdir] Created dir: C:\junk\classes
[mkdir] Created dir: C:\junk\pub
hbm2ddl:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2ddl (Generates database schema)
[hibernatetool] log4j:WARN No appenders could be found for logger (org.hibernate
.cfg.Environment).
[hibernatetool] log4j:WARN Please initialize the log4j system properly.
[hibernatetool] create table EVENTS (EVENT_ID bigint not null auto_increment, EV
ENT_DATE datetime, TITLE varchar(255), primary key (EVENT_ID));
[hibernatetool] create table PERSON (PERSON_ID bigint not null auto_increment, A
GE integer, FirstName varchar(255), LastName varchar(255), primary key (PERSON_I
D));
hbm2java:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: hbm2java (Generates a set of .java files)
echo:
[echo] C:\apache-ant-1.6.5\lib\ant-launcher.jar;C:\apache-ant-1.6.5\lib\ant
-antlr.jar;C:\apache-ant-1.6.5\lib\ant-apache-bcel.jar;C:\apache-ant-1.6.5\lib\a
nt-apache-bsf.jar;C:\apache-ant-1.6.5\lib\ant-apache-log4j.jar;C:\apache-ant-1.6
.5\lib\ant-apache-oro.jar;C:\apache-ant-1.6.5\lib\ant-apache-regexp.jar;C:\apach
e-ant-1.6.5\lib\ant-apache-resolver.jar;C:\apache-ant-1.6.5\lib\ant-commons-logg
ing.jar;C:\apache-ant-1.6.5\lib\ant-commons-net.jar;C:\apache-ant-1.6.5\lib\ant-
icontract.jar;C:\apache-ant-1.6.5\lib\ant-jai.jar;C:\apache-ant-1.6.5\lib\ant-ja
vamail.jar;C:\apache-ant-1.6.5\lib\ant-jdepend.jar;C:\apache-ant-1.6.5\lib\ant-j
mf.jar;C:\apache-ant-1.6.5\lib\ant-jsch.jar;C:\apache-ant-1.6.5\lib\ant-junit.ja
r;C:\apache-ant-1.6.5\lib\ant-launcher.jar;C:\apache-ant-1.6.5\lib\ant-netrexx.j
ar;C:\apache-ant-1.6.5\lib\ant-nodeps.jar;C:\apache-ant-1.6.5\lib\ant-starteam.j
ar;C:\apache-ant-1.6.5\lib\ant-stylebook.jar;C:\apache-ant-1.6.5\lib\ant-swing.j
ar;C:\apache-ant-1.6.5\lib\ant-trax.jar;C:\apache-ant-1.6.5\lib\ant-vaj.jar;C:\a
pache-ant-1.6.5\lib\ant-weblogic.jar;C:\apache-ant-1.6.5\lib\ant-xalan1.jar;C:\a
pache-ant-1.6.5\lib\ant-xslp.jar;C:\apache-ant-1.6.5\lib\ant.jar;C:\apache-ant-1
.6.5\lib\xercesImpl.jar;C:\apache-ant-1.6.5\lib\xml-apis.jar;C:\jdk1.5.0_15\lib\
tools.jar
hbm2dao:
[hibernatetool] Executing Hibernate Tool with a Standard Configuration
[hibernatetool] 1. task: generic exportertemplate: C:/junk/config/CustomDAOTempl
ate.ftl
[hibernatetool] An exception occurred while running exporter #2:generic exporter
template: C:/junk/config/CustomDAOTemplate.ftl
[hibernatetool] To get the full stack trace run ant with -verbose
[hibernatetool] org.hibernate.tool.hbm2x.ExporterException: Error while processi
ng template C:/junk/config/CustomDAOTemplate.ftl
[hibernatetool] java.io.FileNotFoundException: Template C:/junk/config/CustomDAO
Template.ftl not found.
BUILD FAILED
C:\junk\build.xml:142: org.hibernate.tool.hbm2x.ExporterException: Error while p
rocessing template C:/junk/config/CustomDAOTemplate.ftl
at org.hibernate.tool.ant.HibernateToolTask.reportException(HibernateToo
lTask.java:223)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.ja
va:186)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
Caused by: org.hibernate.tool.hbm2x.ExporterException: Error while processing te
mplate C:/junk/config/CustomDAOTemplate.ftl
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelpe
r.java:250)
at org.hibernate.tool.hbm2x.TemplateProducer.produceToString(TemplatePro
ducer.java:67)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.ja
va:28)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.ja
va:97)
at org.hibernate.tool.hbm2x.GenericExporter.exportPOJO(GenericExporter.j
ava:146)
at org.hibernate.tool.hbm2x.GenericExporter.exportPersistentClass(Generi
cExporter.java:135)
at org.hibernate.tool.hbm2x.GenericExporter$2.process(GenericExporter.ja
va:41)
at org.hibernate.tool.hbm2x.GenericExporter.doStart(GenericExporter.java
:126)
at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java
:95)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:40)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.ja
va:183)
... 12 more
Caused by: java.io.FileNotFoundException: Template C:/junk/config/CustomDAOTempl
ate.ftl not found.
at freemarker.template.Configuration.getTemplate(Configuration.java:489)
at freemarker.template.Configuration.getTemplate(Configuration.java:452)
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelpe
r.java:246)
... 22 more
--- Nested Exception ---
org.hibernate.tool.hbm2x.ExporterException: Error while processing template C:/j
unk/config/CustomDAOTemplate.ftl
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelpe
r.java:250)
at org.hibernate.tool.hbm2x.TemplateProducer.produceToString(TemplatePro
ducer.java:67)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.ja
va:28)
at org.hibernate.tool.hbm2x.TemplateProducer.produce(TemplateProducer.ja
va:97)
at org.hibernate.tool.hbm2x.GenericExporter.exportPOJO(GenericExporter.j
ava:146)
at org.hibernate.tool.hbm2x.GenericExporter.exportPersistentClass(Generi
cExporter.java:135)
at org.hibernate.tool.hbm2x.GenericExporter$2.process(GenericExporter.ja
va:41)
at org.hibernate.tool.hbm2x.GenericExporter.doStart(GenericExporter.java
:126)
at org.hibernate.tool.hbm2x.AbstractExporter.start(AbstractExporter.java
:95)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:40)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.ja
va:183)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1216)
at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExe
cutor.java:40)
at org.apache.tools.ant.Project.executeTargets(Project.java:1068)
at org.apache.tools.ant.Main.runBuild(Main.java:668)
at org.apache.tools.ant.Main.startAnt(Main.java:187)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
Caused by: java.io.FileNotFoundException: Template C:/junk/config/CustomDAOTempl
ate.ftl not found.
at freemarker.template.Configuration.getTemplate(Configuration.java:489)
at freemarker.template.Configuration.getTemplate(Configuration.java:452)
at org.hibernate.tool.hbm2x.TemplateHelper.processTemplate(TemplateHelpe
r.java:246)
... 22 more
Total time: 4 seconds
C:\junk>
Kindly look build.xml file ::
Code:
<?xml version="1.0"?>
<project name="hibernate-tutorial" default="createjar">
<property name="base" value="."/>
<property name="hibernateConfigdir" value="${base}/config"/>
<property name="hibernateSourcedir" value="${base}/hibernate-src"/>
<property name="generatedSourcedir" value="${base}/src"/>
<property name="generatedsqldir" value="${base}/sql"/>
<property name="generateddocdir" value="${base}/doc"/>
<property name="generateddaodir" value="${base}/dao"/>
<property name="generatedhbmdir" value="${base}/hbm"/>
<property name="librarydir" value="${base}/lib"/>
<property name="build.dir" value="${base}/classes"/>
<property name="release.dir" value="${base}/pub"/>
<path id="toolslib">
<pathelement location="${librarydir}/hibernate-tools.jar" />
<pathelement location="${librarydir}/hibernate3.jar" />
<pathelement location="${librarydir}/freemarker.jar" />
<pathelement location="${librarydir}/commons-logging-1.0.4.jar" />
<pathelement location="${librarydir}/dom4j-1.6.1.jar" />
<pathelement location="${librarydir}/commons-collections-2.1.1.jar" />
<pathelement location="${librarydir}/log4j-1.2.15.jar" />
<pathelement location="${librarydir}/slf4j-api-1.5.0.jar" />
<pathelement location="${librarydir}/jtidy-r8-20060801.jar" />
<pathelement location="${librarydir}/slf4j-log4j12-1.5.0.jar" />
<pathelement location="${librarydir}/mssqlserver.jar" />
<pathelement location="${librarydir}/msutil.jar" />
<pathelement location="${librarydir}/msbase.jar" />
<pathelement location="${librarydir}/mysql-connector-java-3.1.13-bin.jar" />
<pathelement location="${librarydir}/spring-2.5.1.jar" />
</path>
<taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="toolslib" />
<target name="hbm2java">
<hibernatetool destdir="${generatedSourcedir}">
<!--<classpath>
<path location="${generatedSourcedir}/classes"/>
</classpath>-->
<configuration configurationfile="${hibernateConfigdir}/hibernate.cfg.xml">
<fileset dir="${hibernateSourcedir}/events">
<include name="**/*.hbm.xml"/>
</fileset>
</configuration>
<hbm2java jdk5="true" ejb3="false"/>
</hibernatetool>
</target>
<target name="hbm2ddl">
<hibernatetool destdir="${generatedsqldir}">
<configuration configurationfile="${hibernateConfigdir}/hibernate.cfg.xml">
<fileset dir="${hibernateSourcedir}/events">
<include name="**/*.hbm.xml"/>
</fileset>
</configuration>
<hbm2ddl export="false" outputfilename="sql.ddl"/>
</hibernatetool>
</target>
<target name="hbm2doc">
<hibernatetool destdir="${generateddocdir}">
<configuration configurationfile="${hibernateConfigdir}/hibernate.cfg.xml">
<fileset dir="${hibernateSourcedir}/events">
<include name="**/*.hbm.xml"/>
</fileset>
</configuration>
<hbm2doc/>
</hibernatetool>
</target>
<target name="hbm2hbmxml">
<hibernatetool destdir="${generatedhbmdir}">
<configuration configurationfile="${hibernateConfigdir}/hibernate.cfg.xml">
<fileset dir="${hibernateSourcedir}/events">
<include name="**/*.hbm.xml"/>
</fileset>
</configuration>
<hbm2hbmxml/>
</hibernatetool>
</target>
<target name="echo">
<echo message="${java.class.path}" />
</target>
<target name="hbm2dao">
<hibernatetool destdir="${generateddaodir}">
<classpath>
<path location="${hibernateConfigdir}"/>
</classpath>
<property key="ejb3" value="false"/>
<property key="jdk5" value="true"/>
<configuration configurationfile="${hibernateConfigdir}/hibernate.cfg.xml">
<fileset dir="${hibernateSourcedir}/events">
<include name="**/*.hbm.xml"/>
</fileset>
</configuration>
<hbmtemplate template="C:/junk/config/CustomDAOTemplate.ftl" filepattern="{package-name}/{class-name}DAO.java"/>
<!--<hbmtemplate template="${hibernateConfigdir}/my_daohome.vm" filepattern="{package-name}/{class-name}DAO.java"/>-->
</hibernatetool>
</target>
<target name="compile" description="Compile all POJO java files">
<javac destdir="${build.dir}" failonerror="true" srcdir="${generatedSourcedir}:${generateddaodir}" >
<classpath refid="toolslib"/>
<exclude name="**/*Home.java"/>
</javac>
</target>
<target name="clean"
description="clean up and create folders" >
<delete dir="${generatedSourcedir}"/>
<delete dir="${generateddaodir}"/>
<delete dir="${generatedsqldir}"/>
<delete dir="${generatedhbmdir}"/>
<delete dir="${build.dir}"/>
<delete dir="${release.dir}"/>
<mkdir dir="${generatedSourcedir}"/>
<mkdir dir="${generateddaodir}"/>
<mkdir dir="${generatedsqldir}"/>
<mkdir dir="${generatedhbmdir}"/>
<mkdir dir="${build.dir}"/>
<mkdir dir="${release.dir}"/>
</target>
<!--create jar which is a set of all java class files-->
<target name="createjar" depends="clean,hbm2ddl,hbm2java,echo,hbm2dao,hbm2hbmxml,hbm2doc,compile">
<jar destfile="${release.dir}/app.jar" basedir="${build.dir}"/>
</target>
</project>
Please give your important suggestions to resolve this problem.
Regards,
-Shobhit Singh
India