gpt4 book ai didi

java - 使用扭矩生成模式文件 4

转载 作者:行者123 更新时间:2023-11-30 11:28:23 26 4
gpt4 key购买 nike

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

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

那么我是否必须使用 torque 4 手动编写我的 xml 模式文件,或者有没有办法像 torque 3 那样从 sql 或实时数据库自动生成它们?

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

看来我的 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>

最佳答案

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>

关于java - 使用扭矩生成模式文件 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18879013/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com