-->
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.  [ 9 posts ] 
Author Message
 Post subject: problm with defining class path
PostPosted: Wed Jul 12, 2006 6:22 am 
Newbie

Joined: Sun Jul 09, 2006 3:21 am
Posts: 15
i write this build.xml but dont work ,
it cannot find the jdbc driver
maybe i have defined the class path wrongly
what is the problem ?



build.xml file :

<?xml version="1.0"?>

<project default="main" basedir=".">
<property file="build.properties"/>

<target name="main" depends="prepare, generate"/>

<target name="prepare">

<taskdef name="hibernatetool"
classname="org.hibernate.tool.ant.HibernateToolTask">
<classpath>
<fileset dir="${hibernate.tools.dir}">
<include name="**/*.jar" />
</fileset>
<fileset dir="C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib">
<include name="**/*.jar" />
</fileset>
</classpath>
</taskdef>

<hibernatetool destdir="${build.classes.dir}">
<jdbcconfiguration configurationfile="hibernate.cfg.xml" />
<property key="jdk5" value="true"/>
<property key="ejb3" value="false"/>

<hbm2hbmxml destdir="${build.classes.dir}"/>
</hibernatetool>
</target>

<target name="generate" >
</target>

</project>



build.properties :

build.classes.dir=${basedir}/salam

hibernate.plugin.dir=D:/code.java/hibernate
hibernate.tools.dir=${hibernate.plugin.dir}/lib/tools
hibernate.libs.lib=${hibernate.plugin.dir}/lib
hibernate.libs.dir=${hibernate.plugin.dir}/lib/hibernate
hibernate.libs.annotations=${hibernate.plugin.dir}/lib/annotations



D:\DevDesk\hibernateToolsTest\src\build.xml:22: org.hibernate.HibernateException: JDBC Driver class not found: com.microsoft.jdbc.sqlserver.SQLServerDriver
at org.hibernate.tool.ant.HibernateToolTask.reportException(HibernateToolTask.java:194)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:163)
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 com.aria.util.antUtil.AntRunner.runTask(AntRunner.java:23)
at com.aria.util.antUtil.test.AntRunnerTester.testRunTask(AntRunnerTester.java:25)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at com.intellij.rt.execution.junit2.IdeaJUnitAgent.doRun(IdeaJUnitAgent.java:58)
at junit.textui.TestRunner.start(TestRunner.java:172)
at com.intellij.rt.execution.junit.TextTestRunner2.startRunnerWithArgs(TextTestRunner2.java:23)
at com.intellij.rt.execution.junit2.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:98)
at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:32)
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:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: org.hibernate.HibernateException: JDBC Driver class not found: com.microsoft.jdbc.sqlserver.SQLServerDriver
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:385)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:61)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:38)
at org.hibernate.tool.ant.JDBCConfigurationTask.doConfiguration(JDBCConfigurationTask.java:76)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:226)
at org.hibernate.tool.ant.HibernateToolTask.getProperties(HibernateToolTask.java:242)
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.java:94)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:39)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:160)
... 31 more
Caused by: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:102)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
... 44 more
--- Nested Exception ---
org.hibernate.HibernateException: JDBC Driver class not found: com.microsoft.jdbc.sqlserver.SQLServerDriver
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:385)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:61)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:38)
at org.hibernate.tool.ant.JDBCConfigurationTask.doConfiguration(JDBCConfigurationTask.java:76)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:226)
at org.hibernate.tool.ant.HibernateToolTask.getProperties(HibernateToolTask.java:242)
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.java:94)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:39)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:160)
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 com.aria.util.antUtil.AntRunner.runTask(AntRunner.java:23)
at com.aria.util.antUtil.test.AntRunnerTester.testRunTask(AntRunnerTester.java:25)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at com.intellij.rt.execution.junit2.IdeaJUnitAgent.doRun(IdeaJUnitAgent.java:58)
at junit.textui.TestRunner.start(TestRunner.java:172)
at com.intellij.rt.execution.junit.TextTestRunner2.startRunnerWithArgs(TextTestRunner2.java:23)
at com.intellij.rt.execution.junit2.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:98)
at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:32)
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:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:102)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
... 44 more


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 12, 2006 6:44 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
check to see if the classpath is actually correct, e.g contains the relevant jar and that the driver class you are referring to is in it.

you should be able to see the resulting classpath by running ant with -verbose or -debug flag.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 15, 2006 6:54 am 
Newbie

Joined: Sun Jul 09, 2006 3:21 am
Posts: 15
hello to everybody and special thanks for max

i use java code to run ant tasks
i write a code that use hibernate tools in it and i must use the ant api to run hibernate tools task

i write a sample code to generate hbmxml files , this code works correctly when i give classpath in my module settings like this : "java.exe -classpath ... "
but i must configure this path in ant not in my module setting

this is my sample code :
HibernateToolTask t = new HibernateToolTask();
Project project = new Project();
project.setBaseDir(new File("D:/DevDesk/hibernateToolsTest/src"));
Path p = new Path(project);

p.add(new Path(project, "C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/msbase.jar"));
p.add(new Path(project, "C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/mssqlserver.jar"));
p.add(new Path(project, "C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/msutil.jar"));

t.setClasspath(p);

JDBCConfigurationTask ct = t.createJDBCConfiguration();
ct.setProject(project);
ct.setConfigurationFile(new File("D:/DevDesk/hibernateToolsTest/src/hibernate.cfg.xml"));
ct.setPackageName("aria.roohi");

Configuration cfg = ct.getConfiguration();
t.setDestDir(new File("D:/DevDesk/hibernateToolsTest/src/generated"));
t.createHbm2HbmXml();
AntRunner ar = new AntRunner();
ar.runTask(t, "D:/DevDesk/hibernateToolsTest/src");



when i run it , this exception occure :

org.hibernate.HibernateException: JDBC Driver class not found: com.microsoft.jdbc.sqlserver.SQLServerDriver
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:66)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:385)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:61)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1881)
at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:38)
at org.hibernate.tool.ant.JDBCConfigurationTask.doConfiguration(JDBCConfigurationTask.java:76)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
at com.aria.util.antUtil.test.AntRunnerTester.testHbm2HbmXml(AntRunnerTester.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:32)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:102)
at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:61)
... 32 more



and when i comment this line : Configuration cfg = ct.getConfiguration();
this exception occure :

org.hibernate.exception.JDBCConnectionException: Getting database metadata
at org.hibernate.tool.ant.HibernateToolTask.reportException(HibernateToolTask.java:194)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:163)
at com.aria.util.antUtil.AntRunner.runTask(AntRunner.java:38)
at com.aria.util.antUtil.test.AntRunnerTester.testHbm2HbmXml(AntRunnerTester.java:115)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at com.intellij.rt.execution.junit2.IdeaJUnitAgent.doRun(IdeaJUnitAgent.java:58)
at junit.textui.TestRunner.start(TestRunner.java:172)
at com.intellij.rt.execution.junit.TextTestRunner2.startRunnerWithArgs(TextTestRunner2.java:23)
at com.intellij.rt.execution.junit2.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:98)
at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:32)
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:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: org.hibernate.exception.JDBCConnectionException: Getting database metadata
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getMetaData(JDBCMetaDataDialect.java:61)
at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getTables(JDBCMetaDataDialect.java:70)
at org.hibernate.cfg.reveng.JDBCReader.processTables(JDBCReader.java:404)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:68)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:781)
at org.hibernate.cfg.JDBCBinder.readDatabaseSchema(JDBCBinder.java:115)
at org.hibernate.cfg.JDBCBinder.readFromDatabase(JDBCBinder.java:87)
at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:40)
at org.hibernate.tool.ant.JDBCConfigurationTask.doConfiguration(JDBCConfigurationTask.java:76)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:226)
at org.hibernate.tool.ant.HibernateToolTask.getProperties(HibernateToolTask.java:242)
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.java:94)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:39)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:160)
... 25 more
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getConnection(JDBCMetaDataDialect.java:294)
at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getMetaData(JDBCMetaDataDialect.java:58)
... 39 more
--- Nested Exception ---
org.hibernate.exception.JDBCConnectionException: Getting database metadata
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:74)
at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getMetaData(JDBCMetaDataDialect.java:61)
at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getTables(JDBCMetaDataDialect.java:70)
at org.hibernate.cfg.reveng.JDBCReader.processTables(JDBCReader.java:404)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:68)
at org.hibernate.cfg.reveng.JDBCReader.readDatabaseSchema(JDBCReader.java:781)
at org.hibernate.cfg.JDBCBinder.readDatabaseSchema(JDBCBinder.java:115)
at org.hibernate.cfg.JDBCBinder.readFromDatabase(JDBCBinder.java:87)
at org.hibernate.cfg.JDBCMetaDataConfiguration.readFromJDBC(JDBCMetaDataConfiguration.java:40)
at org.hibernate.tool.ant.JDBCConfigurationTask.doConfiguration(JDBCConfigurationTask.java:76)
at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:55)
at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:226)
at org.hibernate.tool.ant.HibernateToolTask.getProperties(HibernateToolTask.java:242)
at org.hibernate.tool.ant.ExporterTask.configureExporter(ExporterTask.java:94)
at org.hibernate.tool.ant.ExporterTask.execute(ExporterTask.java:39)
at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:160)
at com.aria.util.antUtil.AntRunner.runTask(AntRunner.java:38)
at com.aria.util.antUtil.test.AntRunnerTester.testHbm2HbmXml(AntRunnerTester.java:115)
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:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at com.intellij.rt.execution.junit2.IdeaJUnitAgent.doRun(IdeaJUnitAgent.java:58)
at junit.textui.TestRunner.start(TestRunner.java:172)
at com.intellij.rt.execution.junit.TextTestRunner2.startRunnerWithArgs(TextTestRunner2.java:23)
at com.intellij.rt.execution.junit2.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:98)
at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:32)
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:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getConnection(DriverManager.java:545)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getConnection(JDBCMetaDataDialect.java:294)
at org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect.getMetaData(JDBCMetaDataDialect.java:58)
... 39 more


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 15, 2006 6:55 am 
Newbie

Joined: Sun Jul 09, 2006 3:21 am
Posts: 15
_


Last edited by srmo642002 on Sat Jul 15, 2006 6:59 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 15, 2006 6:56 am 
Newbie

Joined: Sun Jul 09, 2006 3:21 am
Posts: 15
_


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 16, 2006 5:25 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the driver has to be in the classpath of the <taskdef>; you will have to mimick that in your programmatic api access.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 2:32 am 
Newbie

Joined: Sun Jul 09, 2006 3:21 am
Posts: 15
hello
when i specify classpath by java.exe -classpath and create a new instance of HibernateToolTask , the hibernateToolTask that loaded by java class loader wants to load jdbcDriver by his classloader and and this class loader hasnt the path of jdbcDriver ,,,
i use reflection to resolve this problem ,,


try {
Project project = new Project();
project.setBaseDir(new File("D:/DevDesk/hibernateToolsTest/src"));
Path p = new Path(project);
// Reference reference = new Reference();
// reference.setRefId("toolslib");
// p.setRefid(reference);

p.add(new Path(project, "D:/DevDesk/hibernateToolsTest/src"));
p.add(new Path(project, "D:/code.java/hibernate-tools/lib/tools/hibernate-tools.jar"));
p.add(new Path(project, "D:/code.java/hibernate-tools/lib/hibernate/hibernate3.jar"));
p.add(new Path(project, "D:/code.java/hibernate-tools/lib/tools/freemarker.jar"));
p.add(new Path(project, "D:/code.java/hibernate-tools/lib/tools/jtidy-r8-21122004.jar"));
p.add(new Path(project, "D:/code.java/hibernate-tools/lib/hibernate/dom4j-1.6.1.jar"));
p.add(new Path(project, "D:/code.java/hibernate-tools/lib/hibernate/log4j-1.2.11.jar"));
p.add(new Path(project, "D:/code.java/hibernate-tools/lib/hibernate/commons-logging-1.0.4.jar"));
p.add(new Path(project, "D:/code.java/hibernate-tools/lib/hibernate/commons-collections-2.1.1.jar"));
p.add(new Path(project, "D:/code.java/hibernate-tools/lib/hibernate/cglib-2.1.3.jar"));
p.add(new Path(project, "D:/code.java/hibernate-tools/lib/hibernate/ehcache-1.1.jar"));
p.add(new Path(project, "D:/code.java/hibernate-tools/lib/hibernate/jta.jar"));
p.add(new Path(project, "C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/msbase.jar"));
p.add(new Path(project, "C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/mssqlserver.jar"));
p.add(new Path(project, "C:/Program Files/Microsoft SQL Server 2000 Driver for JDBC/lib/msutil.jar"));


Taskdef hibernatetool = new Taskdef();
hibernatetool.setName("hibernatetool");
hibernatetool.setClassname("org.hibernate.tool.ant.HibernateToolTask");
// hibernatetool.setClasspathRef(reference);
hibernatetool.setClasspath(p);
hibernatetool.init();
hibernatetool.reconfigure();

Task htt = null;// new HibernateToolTask();
Class hibernateToolTaskClass = null;

AntClassLoader classLoader = project.createClassLoader(p);
//classLoader.setIsolated(true);
classLoader.setParentFirst(false);
//classLoader.setParent(this.getClass().getClassLoader());
//classLoader.setParentFirst(false);
hibernateToolTaskClass = classLoader.findClass("org.hibernate.tool.ant.HibernateToolTask");
htt = (Task) hibernateToolTaskClass.newInstance();
// Class<HibernateToolTask> cls=(Class<HibernateToolTask>) o.getClass();
// htt=cls.cast(o);
// System.out.println(o.getClass());//.cast(o);


Target pojo = new Target();
pojo.setName("pojo");
pojo.setDescription("generate java pojo classes with hbm2java");

//HibernateToolTask t = new HibernateToolTask();
Method createJDBCConfiguration = hibernateToolTaskClass.getMethod("createJDBCConfiguration");
Object jDBCConfigurationTask = createJDBCConfiguration.invoke(htt);
//JDBCConfigurationTask ct=(JDBCConfigurationTask)jDBCConfigurationTask;


Method setProject = jDBCConfigurationTask.getClass().getMethod("setProject", project.getClass());
setProject.invoke(jDBCConfigurationTask, project);
//ct.setProject(project);

Method setConfigurationFile = jDBCConfigurationTask.getClass().getMethod("setConfigurationFile", File.class);
setConfigurationFile.invoke(jDBCConfigurationTask, new File("D:/DevDesk/hibernateToolsTest/src/hibernate.cfg.xml"));
//ct.setConfigurationFile(new File("D:/DevDesk/hibernateToolsTest/src/hibernate.cfg.xml"));

Method setPackageName = jDBCConfigurationTask.getClass().getMethod("setPackageName", String.class);
setPackageName.invoke(jDBCConfigurationTask, new String("aria.roohi"));
//ct.setPackageName("aria.roohi");

Method getConfiguration = jDBCConfigurationTask.getClass().getMethod("getConfiguration");
//Object cfg =getConfiguration.invoke(jDBCConfigurationTask);
//Object cfg = ct.getConfiguration();

Method setDestDir = hibernateToolTaskClass.getMethod("setDestDir", File.class);
setDestDir.invoke(htt, new File("D:/DevDesk/hibernateToolsTest/src/generated"));
//htt.setDestDir(new File("D:/DevDesk/hibernateToolsTest/src/generated"));

Method createHbm2HbmXml = hibernateToolTaskClass.getMethod("createHbm2HbmXml");
createHbm2HbmXml.invoke(htt);
//htt.createHbm2HbmXml();


pojo.addTask(htt);

AntRunner ar = new AntRunner();
ar.runTask(htt, "D:/DevDesk/hibernateToolsTest/src");
} catch (Exception e) {
e.printStackTrace();
}



this code work correctly ,,
are there any better idea ???


Top
 Profile  
 
 Post subject: -
PostPosted: Tue Jul 18, 2006 2:34 am 
Newbie

Joined: Sun Jul 09, 2006 3:21 am
Posts: 15
-


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 18, 2006 3:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
this is more an ant question than tool question.

Why do you want to do this programmatically anyhow ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.