7

我想用 Ant 生成我的数据库模式。我正在使用 hbm2ddl 任务。

我正在使用带有 JNDI 的 Hibernate。我的 hibernate.cfg.xml 看起来像:

<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
    <session-factory>
        <!-- Database connection settings -->
        <property name="connection.datasource">java:comp/env/jdbc/my_app</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="current_session_context_class">thread</property>

            <!-- Mapping -->   
  </session-factory>  
</hibernate-configuration>

我的 $CATALINA_HOME/webapps/myapp/META-INF/context.xml 看起来像:

<Context>
    <Resource name="jdbc/my_app" 
            global="jdbc/my_app"
            auth="Container"
            type="javax.sql.DataSource" 
            username="userA"
            password="userA123"
            driverClassName="com.mysql.jdbc.Driver"
            url="jdbc:mysql://localhost:3306/myapp?autoReconnect=true"
            maxActive="8" 
            maxIdle="4"/>
</Context> 

在 $CATALINA_HOME/webapps/myapp/WEB-INF/web.xml 我有:

     <resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/my_app</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref> 

build.xml我有下一个目标。

<target name="schema" description="Generate DB schema from the O/R mapping files">
    <hibernatetool destdir="${basedir}">
        <classpath path="${java.src.home}">
          <fileset dir="${java.src.home}">
                  <include name="**/*.hbm.xml"/>
          </fileset>
        </classpath>
    <configuration configurationfile="${java.src.home}/hibernate.cfg.xml"/>         
        <hbm2ddl 
            drop="true" 
            create="true"
            export="true"
            outputfilename="myapp-ddl.sql"
            delimiter=";"
            format="true"/>       
    </hibernatetool>
</target>

问题是 ant 没有找到存储在 context.xml 中的 Resource 元素。

[hibernatetool] Error #1: org.hibernate.HibernateException: Could not find datasource

我尝试在类路径元素中添加 nex 片段,但没有成功。

 <fileset dir="${web.home}/META-INF">
       <include name="context.xml"/>
   </fileset> 

如何让 Ant 找到 context.xml 中定义的资源?

我发布了一个完整的错误堆栈跟踪。

[hibernatetool] INFO: JNDI InitialContext properties:{}
[hibernatetool] java.util.zip.ZipException: error in opening zip file
[hibernatetool]     at java.util.zip.ZipFile.open(Native Method)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:114)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:131)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1014)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:146)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.<init>(AntClassLoader.java:108)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.findResources(AntClassLoader.java:958)
[hibernatetool]     at java.lang.ClassLoader.getResources(ClassLoader.java:1016)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12$5.run(VersionHelper12.java:149)
[hibernatetool]     at java.security.AccessController.doPrivileged(Native Method)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12.getResources(VersionHelper12.java:146)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getApplicationResources(ResourceManager.java:468)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getInitialEnvironment(ResourceManager.java:159)
[hibernatetool]     at javax.naming.InitialContext.init(InitialContext.java:219)
[hibernatetool]     at javax.naming.InitialContext.<init>(InitialContext.java:175)
[hibernatetool]     at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
[hibernatetool]     at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:27)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
[hibernatetool]     at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:55)
[hibernatetool]     at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:171)
[hibernatetool]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[hibernatetool]     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
[hibernatetool]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[hibernatetool]     at java.lang.reflect.Method.invoke(Method.java:597)
[hibernatetool]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[hibernatetool]     at org.apache.tools.ant.Task.perform(Task.java:348)
[hibernatetool]     at org.apache.tools.ant.Target.execute(Target.java:357)
[hibernatetool]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
[hibernatetool]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[hibernatetool]     at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[hibernatetool]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[hibernatetool]     at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
[hibernatetool] java.util.zip.ZipException: error in opening zip file
[hibernatetool]     at java.util.zip.ZipFile.open(Native Method)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:114)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:131)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1014)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:146)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.<init>(AntClassLoader.java:108)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.findResources(AntClassLoader.java:958)
[hibernatetool]     at java.lang.ClassLoader.getResources(ClassLoader.java:1016)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12$5.run(VersionHelper12.java:149)
[hibernatetool]     at java.security.AccessController.doPrivileged(Native Method)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12.getResources(VersionHelper12.java:146)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getApplicationResources(ResourceManager.java:468)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getInitialEnvironment(ResourceManager.java:159)
[hibernatetool]     at javax.naming.InitialContext.init(InitialContext.java:219)
[hibernatetool]     at javax.naming.InitialContext.<init>(InitialContext.java:175)
[hibernatetool]     at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
[hibernatetool]     at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:27)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
[hibernatetool]     at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:55)
[hibernatetool]     at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:171)
[hibernatetool]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[hibernatetool]     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
[hibernatetool]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[hibernatetool]     at java.lang.reflect.Method.invoke(Method.java:597)
[hibernatetool]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[hibernatetool]     at org.apache.tools.ant.Task.perform(Task.java:348)
[hibernatetool]     at org.apache.tools.ant.Target.execute(Target.java:357)
[hibernatetool]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
[hibernatetool]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[hibernatetool]     at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[hibernatetool]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[hibernatetool]     at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
[hibernatetool] java.util.zip.ZipException: error in opening zip file
[hibernatetool]     at java.util.zip.ZipFile.open(Native Method)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:114)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:131)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1014)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:146)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.<init>(AntClassLoader.java:108)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.findResources(AntClassLoader.java:958)
[hibernatetool]     at java.lang.ClassLoader.getResources(ClassLoader.java:1016)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12$5.run(VersionHelper12.java:149)
[hibernatetool]     at java.security.AccessController.doPrivileged(Native Method)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12.getResources(VersionHelper12.java:146)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getApplicationResources(ResourceManager.java:468)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getInitialEnvironment(ResourceManager.java:159)
[hibernatetool]     at javax.naming.InitialContext.init(InitialContext.java:219)
[hibernatetool]     at javax.naming.InitialContext.<init>(InitialContext.java:175)
[hibernatetool]     at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
[hibernatetool]     at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:27)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
[hibernatetool]     at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:55)
[hibernatetool]     at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:171)
[hibernatetool]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[hibernatetool]     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
[hibernatetool]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[hibernatetool]     at java.lang.reflect.Method.invoke(Method.java:597)
[hibernatetool]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[hibernatetool]     at org.apache.tools.ant.Task.perform(Task.java:348)
[hibernatetool]     at org.apache.tools.ant.Target.execute(Target.java:357)
[hibernatetool]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
[hibernatetool]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[hibernatetool]     at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[hibernatetool]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[hibernatetool]     at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
[hibernatetool] java.util.zip.ZipException: error in opening zip file
[hibernatetool]     at java.util.zip.ZipFile.open(Native Method)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:114)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:131)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1014)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:146)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.<init>(AntClassLoader.java:108)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.findResources(AntClassLoader.java:958)
[hibernatetool]     at java.lang.ClassLoader.getResources(ClassLoader.java:1016)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12$5.run(VersionHelper12.java:149)
[hibernatetool]     at java.security.AccessController.doPrivileged(Native Method)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12.getResources(VersionHelper12.java:146)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getApplicationResources(ResourceManager.java:468)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getInitialEnvironment(ResourceManager.java:159)
[hibernatetool]     at javax.naming.InitialContext.init(InitialContext.java:219)
[hibernatetool]     at javax.naming.InitialContext.<init>(InitialContext.java:175)
[hibernatetool]     at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
[hibernatetool]     at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:27)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
[hibernatetool]     at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:55)
[hibernatetool]     at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:171)
[hibernatetool]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[hibernatetool]     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
[hibernatetool]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[hibernatetool]     at java.lang.reflect.Method.invoke(Method.java:597)
[hibernatetool]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[hibernatetool]     at org.apache.tools.ant.Task.perform(Task.java:348)
[hibernatetool]     at org.apache.tools.ant.Target.execute(Target.java:357)
[hibernatetool]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
[hibernatetool]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[hibernatetool]     at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[hibernatetool]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[hibernatetool]     at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
[hibernatetool] java.util.zip.ZipException: error in opening zip file
[hibernatetool]     at java.util.zip.ZipFile.open(Native Method)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:114)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:131)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1014)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:146)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.<init>(AntClassLoader.java:108)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.findResources(AntClassLoader.java:958)
[hibernatetool]     at java.lang.ClassLoader.getResources(ClassLoader.java:1016)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12$5.run(VersionHelper12.java:149)
[hibernatetool]     at java.security.AccessController.doPrivileged(Native Method)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12.getResources(VersionHelper12.java:146)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getApplicationResources(ResourceManager.java:468)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getInitialEnvironment(ResourceManager.java:159)
[hibernatetool]     at javax.naming.InitialContext.init(InitialContext.java:219)
[hibernatetool]     at javax.naming.InitialContext.<init>(InitialContext.java:175)
[hibernatetool]     at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
[hibernatetool]     at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:27)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
[hibernatetool]     at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:55)
[hibernatetool]     at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:171)
[hibernatetool]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[hibernatetool]     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
[hibernatetool]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[hibernatetool]     at java.lang.reflect.Method.invoke(Method.java:597)
[hibernatetool]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[hibernatetool]     at org.apache.tools.ant.Task.perform(Task.java:348)
[hibernatetool]     at org.apache.tools.ant.Target.execute(Target.java:357)
[hibernatetool]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
[hibernatetool]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[hibernatetool]     at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[hibernatetool]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[hibernatetool]     at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
[hibernatetool] java.util.zip.ZipException: error in opening zip file
[hibernatetool]     at java.util.zip.ZipFile.open(Native Method)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:114)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:131)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1014)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:146)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.<init>(AntClassLoader.java:108)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.findResources(AntClassLoader.java:958)
[hibernatetool]     at java.lang.ClassLoader.getResources(ClassLoader.java:1016)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12$5.run(VersionHelper12.java:149)
[hibernatetool]     at java.security.AccessController.doPrivileged(Native Method)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12.getResources(VersionHelper12.java:146)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getApplicationResources(ResourceManager.java:468)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getInitialEnvironment(ResourceManager.java:159)
[hibernatetool]     at javax.naming.InitialContext.init(InitialContext.java:219)
[hibernatetool]     at javax.naming.InitialContext.<init>(InitialContext.java:175)
[hibernatetool]     at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
[hibernatetool]     at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:27)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
[hibernatetool]     at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:55)
[hibernatetool]     at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:171)
[hibernatetool]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[hibernatetool]     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
[hibernatetool]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[hibernatetool]     at java.lang.reflect.Method.invoke(Method.java:597)
[hibernatetool]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[hibernatetool]     at org.apache.tools.ant.Task.perform(Task.java:348)
[hibernatetool]     at org.apache.tools.ant.Target.execute(Target.java:357)
[hibernatetool]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
[hibernatetool]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[hibernatetool]     at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[hibernatetool]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.EclipseDefaultExecutor.executeTargets(EclipseDefaultExecutor.java:32)
[hibernatetool]     at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.run(InternalAntRunner.java:423)
[hibernatetool]     at org.eclipse.ant.internal.ui.antsupport.InternalAntRunner.main(InternalAntRunner.java:137)
[hibernatetool] java.util.zip.ZipException: error in opening zip file
[hibernatetool]     at java.util.zip.ZipFile.open(Native Method)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:114)
[hibernatetool]     at java.util.zip.ZipFile.<init>(ZipFile.java:131)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.getResourceURL(AntClassLoader.java:1014)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.findNextResource(AntClassLoader.java:146)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader$ResourceEnumeration.<init>(AntClassLoader.java:108)
[hibernatetool]     at org.apache.tools.ant.AntClassLoader.findResources(AntClassLoader.java:958)
[hibernatetool]     at java.lang.ClassLoader.getResources(ClassLoader.java:1016)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12$5.run(VersionHelper12.java:149)
[hibernatetool]     at java.security.AccessController.doPrivileged(Native Method)
[hibernatetool]     at com.sun.naming.internal.VersionHelper12.getResources(VersionHelper12.java:146)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getApplicationResources(ResourceManager.java:468)
[hibernatetool]     at com.sun.naming.internal.ResourceManager.getInitialEnvironment(ResourceManager.java:159)
[hibernatetool]     at javax.naming.InitialContext.init(InitialContext.java:219)
[hibernatetool]     at javax.naming.InitialContext.<init>(InitialContext.java:175)
[hibernatetool]     at org.hibernate.util.NamingHelper.getInitialContext(NamingHelper.java:28)
[hibernatetool]     at org.hibernate.connection.DatasourceConnectionProvider.configure(DatasourceConnectionProvider.java:52)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:124)
[hibernatetool]     at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:56)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.ManagedProviderConnectionHelper.prepare(ManagedProviderConnectionHelper.java:27)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.execute(SchemaExport.java:180)
[hibernatetool]     at org.hibernate.tool.hbm2ddl.SchemaExport.create(SchemaExport.java:133)
[hibernatetool]     at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:55)
[hibernatetool]     at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:171)
[hibernatetool]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[hibernatetool]     at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
[hibernatetool]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[hibernatetool]     at java.lang.reflect.Method.invoke(Method.java:597)
[hibernatetool]     at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[hibernatetool]     at org.apache.tools.ant.Task.perform(Task.java:348)
[hibernatetool]     at org.apache.tools.ant.Target.execute(Target.java:357)
[hibernatetool]     at org.apache.tools.ant.Target.performTasks(Target.java:385)
[hibernatetool]     at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[hibernatetool]     at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[hibernatetool]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultE
4

1 回答 1

0

这是不可能的。Ant 无法引用您放在 tomcat 中的配置,因为它在容器之外运行。

要从 ant 生成模式,请使用另一个指定连接参数的 hibernate.cfg.xml 文件而不是 JNDI。

于 2012-10-18T00:53:03.090 回答