使用扭矩4生成模式文件

时间:2013-09-18 17:52:01

标签: java maven apache-torque

扭矩4是否失去了从实时数据库生成模式文件的能力?

在扭矩3中,您可以使用“maven torque:jdbc”从数据库生成模式,这很好,但看起来扭矩4已经失去了这种能力。

所以我必须用扭矩4手动编写我的xml架构文件,或者有没有办法从sql或实时数据库中自动生成它们,如扭矩3?

-------------根据评论添加-------

似乎我的pom.xml在某种程度上是错误的。当我尝试运行mvn generate-test-sources

时,我收到以下错误
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Eddie torque generator 1.0.0
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for org.apache.maven.plugins:maven-compiler-plugin:jar:1.0.0 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.197s
[INFO] Finished at: Tue Sep 24 22:43:25 CEST 2013
[INFO] Final Memory: 5M/240M
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-compiler-plugin:1.0.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-compiler-plugin:jar:1.0.0: Failure to find org.apache.maven.plugins:maven-compiler-plugin:pom:1.0.0 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:

我当前的pom.xml是:(可能是疯狂的错误和愚蠢的,因为我之前有更新的maven,我的项目不使用maven任何东西。所以我真的不明白maven是如何工作的。) 。

<?xml version="1.0"?>
<project
    xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>Eddie</groupId>
  <artifactId>eddie</artifactId>
  <packaging>jar</packaging>
  <name>Eddie torque generator</name>
  <version>1.0.0</version>

  <dependencies>
    <!-- Torque runtime -->
    <dependency>
      <artifactId>torque-runtime</artifactId>
      <groupId>org.apache.torque</groupId>
      <version>4.0</version>
    </dependency>

    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>8.4-701.jdbc4</version>
    </dependency>

    <!-- Logging via log4j -->
    <dependency>
      <artifactId>log4j</artifactId>
      <groupId>log4j</groupId>
      <version>1.2.16</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.torque</groupId>
        <artifactId>torque-maven-plugin</artifactId>
        <version>4.0</version>
        <executions>

        <execution>
            <id>generate-sources</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <packaging>classpath</packaging>
              <configPackage>org.apache.torque.templates.om</configPackage>
              <sourceDir>src/schema</sourceDir>
              <options>
                <torque.om.package>dk.mt3.libris.server.auto</torque.om.package>
                <torque.database>postgresql</torque.database>
              </options>
            </configuration>
          </execution>

          <execution>
            <id>generate-sql</id>
            <phase>generate-sources</phase>
            <goals>
              <goal>generate</goal>
            </goals>
            <configuration>
              <packaging>classpath</packaging>
              <configPackage>org.apache.torque.templates.sql</configPackage>
              <sourceDir>src/schema</sourceDir>
              <defaultOutputDir>target/generated-sql</defaultOutputDir>
              <defaultOutputDirUsage>none</defaultOutputDirUsage>
              <options>
                <torque.database>postgresql</torque.database>
              </options>
            </configuration>
          </execution>

<!-- Insert start -->
<execution>
<id>generate-schema-from-jdbc</id>
<phase>generate-test-sources</phase>
<goals>
  <goal>generate</goal>
</goals>
<configuration>
  <packaging>classpath</packaging>
  <configPackage>org.apache.torque.templates.jdbc2schema</configPackage>
  <newFileTargetDir>target/generated-schema</newFileTargetDir>
  <newFileTargetDirUsage>none</newFileTargetDirUsage>
  <options>
  <driver></driver>
  <url></url>
      <username>tiller</username>

  <torque.jdbc2schema.driver>org.postgresql.Driver</torque.jdbc2schema.driver>
    <torque.jdbc2schema.url>jdbc:postgresql://localhost/librisepubcreator</torque.jdbc2schema.url>
    <torque.jdbc2schema.user>tiller</torque.jdbc2schema.user>
    <torque.jdbc2schema.password></torque.jdbc2schema.password>
  </options>
</configuration>
</execution>
<!-- Insert end -->
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.apache.torque</groupId>
            <artifactId>torque-templates</artifactId>
            <version>4.0</version>
          </dependency>
        </dependencies>
      </plugin>

      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>sql-maven-plugin</artifactId>
        <version>1.4</version>
        <configuration>
          <driver>org.postgresql.Driver</driver>
          <url>jdbc:postgresql://localhost/librisepubcreator</url>
          <username>tiller</username>
<!--
          <password></password>
-->
          <onError>continue</onError>
          <autocommit>true</autocommit>
          <fileset>
            <basedir>${basedir}/target/generated-sql</basedir>
            <includes>
              <include>*.sql</include>
            </includes>
          </fileset>
        </configuration>
       </plugin>

      <plugin>
        <!-- setting java version to 1.5 --> 
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>1.0.0</version>

        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
          <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
              <goal>copy-dependencies</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

2 个答案:

答案 0 :(得分:1)

Torque Maven plugin现在只提供“生成”目标。

请参阅Running the Generator部分中的“从现有数据库生成XML架构”。

简而言之,请使用torque.jdbc2schema选项。例如:

<execution>
  <id>generate-schema-from-jdbc</id>
  <phase>generate-test-sources</phase>
  <goals>
    <goal>generate</goal>
  </goals>
  <configuration>
    <packaging>classpath</packaging>
    <configPackage>org.apache.torque.templates.jdbc2schema</configPackage>
    <newFileTargetDir>target/generated-schema</newFileTargetDir>
    <newFileTargetDirUsage>none</newFileTargetDirUsage>
    <options>
      <torque.jdbc2schema.driver>${torque.driver}</torque.jdbc2schema.driver>
      <torque.jdbc2schema.url>${torque.database.url}</torque.jdbc2schema.url>
      <torque.jdbc2schema.user>${torque.database.user}</torque.jdbc2schema.user>
      <torque.jdbc2schema.password>${torque.database.password}</torque.jdbc2schema.password>
      <torque.jdbc2schema.schema>${torque.database.schema}</torque.jdbc2schema.schema>
    </options>
  </configuration>
</execution>

答案 1 :(得分:0)

您必须添加驱动程序依赖项:

...
<dependencies>
      <dependency>
        <groupId>org.apache.torque</groupId>
        <artifactId>torque-templates</artifactId>
        <version>4.0</version>
      </dependency>
       <dependency>
                <groupId>postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <version>8.4-701.jdbc4</version>
         </dependency>
</dependencies>
</plugin>

在你的torque-4插件中。机制是,插件从扭矩模板依赖性中读取所有需要的配置。在这种情况下,来自classpath org.apache.torque.templates.jdbc2schema,其中找到conf和outlet配置。