我为 template 和 templateprefix 尝试了多种组合,但是唯一有效的组合是上面第一个build.gradle文件中的组合. 更新 我尝试使用 templateprefix 和 template 的绝对路径,并得到未找到相同文件的错误.解决方案添加 reverseMap文件('.') 依赖于您.Using the Hibernate ant task from with Gradle I'm able to generate entity classes from a database using the documentation at http://docs.jboss.org/tools/latest/en/hibernatetools/html_single/index.html#d0e5102When I change template and templateprefix, Hibernate cannot find my custom templates. To be sure, I copied the templates directly from the hibernate jars and added a single comment to the Pojo.ftl.Here's my working Gradle build file with the Hibernate templates... below the working build file is the failing one, which is identical except for the template and templateprefix.apply plugin: 'java'repositories { mavenCentral()}configurations { reverseMap}dependencies { reverseMap 'org.hibernate:hibernate-tools:4.0.0-CR1' reverseMap 'org.slf4j:slf4j-simple:1.7.5' reverseMap files('/Users/jzwolak/local/lib/ojdbc6-11.2.0.2.0.jar') compile 'javax:javaee-api:7.0'}project.ext { hibernateRevEngXml = "$projectDir/config/hibernate.reveng.xml" hibernateDestDir = file("$buildDir/generated")}task reverseMap { inputs.files hibernateRevEngXml outputs.dir hibernateDestDir doLast { hibernateDestDir.exists() || hibernateDestDir.mkdirs() ant { taskdef(name: 'hibernatetool', classname: 'org.hibernate.tool.ant.HibernateToolTask', classpath: configurations.reverseMap.asPath ) hibernatetool( destdir : hibernateDestDir ) { jdbcconfiguration( configurationfile:"$projectDir/config/hibernate.cfg.xml", revengfile:hibernateRevEngXml, packagename: "com.mybiz" //reversestrategy="ReverseEngineeringStrategy classname" //detectmanytomany="true|false" //detectoptmisticlock="true|false" ) hbmtemplate( templateprefix:"pojo/" , template:"pojo/Pojo.ftl", filepattern:"{package-name}/{class-name}.java" ) { property(key:"jdk5",value:"true") property(key:"ejb3",value:"true") } /* hbm2java( jdk5: true, ejb3: true ) */ // Adds the config directory to the path so that log4j can pick up // its properties file. classpath { pathelement( path: "config" ) } } } }}compileJava.source reverseMap.outputs.files, sourceSets.main.javaAnd here's the failing build file.apply plugin: 'java'repositories { mavenCentral()}configurations { reverseMap}dependencies { reverseMap 'org.hibernate:hibernate-tools:4.0.0-CR1' reverseMap 'org.slf4j:slf4j-simple:1.7.5' reverseMap files('/Users/jzwolak/local/lib/ojdbc6-11.2.0.2.0.jar') compile 'javax:javaee-api:7.0'}project.ext { hibernateRevEngXml = "$projectDir/config/hibernate.reveng.xml" hibernateDestDir = file("$buildDir/generated")}task reverseMap { inputs.files hibernateRevEngXml outputs.dir hibernateDestDir doLast { hibernateDestDir.exists() || hibernateDestDir.mkdirs() ant { taskdef(name: 'hibernatetool', classname: 'org.hibernate.tool.ant.HibernateToolTask', classpath: configurations.reverseMap.asPath ) hibernatetool( destdir : hibernateDestDir ) { jdbcconfiguration( configurationfile:"$projectDir/config/hibernate.cfg.xml", revengfile:hibernateRevEngXml, packagename: "com.mybiz" //reversestrategy="ReverseEngineeringStrategy classname" //detectmanytomany="true|false" //detectoptmisticlock="true|false" ) hbmtemplate( templateprefix:"templates/custom_pojo/" , template:"templates/custom_pojo/Pojo.ftl", filepattern:"{package-name}/{class-name}.java" ) { property(key:"jdk5",value:"true") property(key:"ejb3",value:"true") } /* hbm2java( jdk5: true, ejb3: true ) */ // Adds the config directory to the path so that log4j can pick up // its properties file. classpath { pathelement( path: "config" ) } } } }}compileJava.source reverseMap.outputs.files, sourceSets.main.javaAnd here's the directory treebuild.gradleconfig| hibernate.cfg.xml| hibernate.reveng.xml| log4j.propertiestemplates| custom_pojo| | Ejb3PropertyGetAnnotation.ftl| | Ejb3TypeDeclaration.ftl| | GetPropertyAnnotation.ftl| | Pojo.ftl| | PojoConstructors.ftl| | PojoEqualsHashcode.ftl| | PojoExtraClassCode.ftl| | PojoFields.ftl| | PojoInterfacePropertyAccessors.ftl| | PojoPropertyAccessors.ftl| | PojoToString.ftl| | PojoTypeDeclaration.ftl| | test.ftlHere's the error[ant:hibernatetool] org.hibernate.tool.hbm2x.ExporterException: Error while processing Entity: com.mybiz.TsModelRealizationView with template templates/custom_pojo/Pojo.ftl[ant:hibernatetool] java.io.FileNotFoundException: Template templates/custom_pojo/Pojo.ftl not found.:reverseMap FAILEDI've tried adding . and templates to the classpath along with config, which is already in the classpath and working.I've tried numerous combinations for template and templateprefix, but the only ones that work are the ones in the first build.gradle file above.UPDATEI tried with absolute paths for templateprefix and template and got the same file not found error. 解决方案 AddreverseMap files('.')to your dependencies. 这篇关于将自定义模板与Hibernate工具一起使用可对Gradle进行反向工程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-14 10:32