In ant build file:
<path id=”groovy.classpath”>
<fileset dir=”${java.groovy}/lib”>
<include name=”*.jar”/>
</fileset>
<fileset dir=”${java.groovy}/embeddable”>
<include name=”*.jar”/>
</fileset>
<pathelement location=”${ext.libs.oracle}/classes12.zip”/>
</path>
<taskdef name=”groovy”
classname=”org.codehaus.groovy.ant.Groovy”
classpathref=”groovy.classpath”/>
<target name=”export.schema.to.file”>
<groovy src=”scripts/export.db.gy”>
<arg line=”${db.url} ${db.schema.owner} ${db.schema.password} ${fileName}”/>
</groovy>
</target>
Groovy script:
import groovy.sql.Sql
import oracle.jdbc.OracleDriver
println “db.url: ” + args[0]
println “db.schema.ownver: ” + args[1]
println “FileName: ” + args[3]
sql = Sql.newInstance(args[0], args[1],
args[2], “oracle.jdbc.OracleDriver”);
new File(args[3]).delete()
new File(args[3]).createNewFile()
def writer=new File(args[3]).newWriter()
sql.eachRow(”SELECT TABLE_NAME FROM user_tables order by TABLE_NAME asc”, {writer.writeLine(it.TABLE_NAME)});
writer.close();
List a =[]
new File(args[3]).eachLine{ line -> a.add(line) }
println(”Total number of tables: ” + a.size());