Maven如何为create-schema命令指定sql文件的目录

时间:2012-11-07 16:13:25

标签: java mysql maven configuration

我有几个包含多个sql文件的目录。如何配置maven来运行目录中的所有sql文件。我当前的配置是这样的:

      <build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sql-maven-plugin</artifactId>
            <version>${sql-maven-plugin.version}</version>
            <dependencies>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>${mysql-connector.version}</version>
                </dependency>
            </dependencies>
            <configuration>
                <driver>${mysql.jdbc.driver.class.name}</driver>
                <url>${mysql.jdbc.url}</url>
                <username>${mysql.jdbc.username}</username>
                <password>${mysql.jdbc.password}</password>
            </configuration>
            <executions>
                <execution>
                    <id>create-schema</id>
                    <phase>install</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <skip>${mysql.db.skip}</skip>
                        <autocommit>true</autocommit>
                        <srcFiles>
<srcFile>src/main/resources/directory1/file1.sql</srcFile>
<srcFile>src/main/resources/directory1/file2.sql</srcFile>
<srcFile>src/main/resources/directory2/file1.sql</srcFile>
<srcFile>src/main/resources/directory2/file2.sql</srcFile>
                        </srcFiles>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
  </build>

每个目录中有许多文件。

如何使用目录而不是列出每个文件?

2 个答案:

答案 0 :(得分:2)

根据documentation,您可以指定文件集,而不是单独列出文件。其中一个例子是here

答案 1 :(得分:0)

在pom.xml中完成基础

 <execution>
        <id>create-data</id>
        <phase>process-test-resources</phase>
        <goals>
          <goal>execute</goal>
        </goals>
        <configuration>
          <orderFile>ascending</orderFile>
          <fileset>
            <basedir>${basedir}</basedir>
            <includes>
              <include>src/test/sql/test-data2.sql</include>
              <include>src/test/sql/test-data1.sql</include>
            </includes>
          </fileset>
        </configuration>
      </execution>