我想要的是能够从 Maven 创建/删除数据库(如果可能的话)。我找到了 maven sql 插件,但不明白如何创建数据库。不知何故,maven 说我没有 sql 命令。谁能帮我解决这个问题?
这是结果
d:\Projects\Learn\hibernate>mvn sql:execute
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building App 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- sql-maven-plugin:1.5:execute (default-cli) @ learn ---
[INFO] 0 of 0 SQL statements executed successfully
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.027s
[INFO] Finished at: Wed Sep 18 11:34:25 MSK 2013
[INFO] Final Memory: 8M/107M
[INFO] ------------------------------------------------------------------------
和pom:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>learn-hibernate</groupId>
<artifactId>learn</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>App</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.build.outputEncoding>UTF-8</project.build.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.5.6-Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<mainClass>App.App</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sql-maven-plugin</artifactId>
<version>1.5</version>
<dependencies>
<!-- specify the dependent jdbc driver here -->
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
</dependencies>
<configuration>
<driver>org.postgresql.Driver</driver>
<url>jdbc:postgresql://localhost:5432</url>
<username>postgres</username>
<password>123456</password>
</configuration>
<executions>
<execution>
<id>default</id>
<phase>compile</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<url>jdbc:postgressql://localhost:5432</url>
<!-- no transaction -->
<autocommit>true</autocommit>
<sqlCommand>create database "hib"</sqlCommand>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>