扭矩 4 是否失去了从实时数据库生成架构文件的能力?
在扭矩 3 中,您可以使用"maven torque:jdbc"从数据库生成模式,这很好,但看起来扭矩 4 已经失去了这种能力。
那么我是否必须使用 torque 4 手动编写我的 xml 模式文件,或者有没有办法像扭矩 3 一样从 sql 或实时数据库自动生成它们?
------------- 根据评论添加-------
看来我的pom.xml不知何故错了。当我尝试运行 mvn 生成测试源时,我收到以下错误
[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>
扭矩Maven插件现在只提供一个"生成"目标。
请参阅运行生成器部分中的"从现有数据库生成 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>
您必须添加驱动程序依赖项:
...
<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>
在您的扭矩 4 插件中。机制是,插件从扭矩模板依赖项中读取所有需要的配置。在本例中,来自类路径 org.apache.torque.templates.jdbc2schema,其中可以找到 conf 和 outlet 配置。