5

下面是我的pom.xml文件:

<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>com.mycompany.app</groupId>
  <artifactId>my-app</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>my-app</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
<build>
  <plugins>
    <plugin>
       <groupId>org.codehaus.mojo</groupId>
    <artifactId>dbunit-maven-plugin</artifactId>
    <version>1.0-beta-3</version>
    <configuration>
    <driver>com.mysql.jdbc.Driver</driver>
    <url>jdbc:mysql://localhost:3306/test</url>
    <username>usernamet</username>
    <password>password</password>
    <dataTypeFactoryName>org.dbunit.ext.mysql.MySqlDataTypeFactory</dataTypeFactoryName>
    <metadataHandlerName>org.dbunit.ext.mysql.MySqlMetadataHandler</metadataHandlerName>
    <encoding>utf-8</encoding>
    <src>target/dbunit/export.xml</src><!--compare 和 operation 要用到它 -->
    <type>CLEAN_INSERT</type><!--operation 要用到它-->
    </configuration>
    <executions> 
<execution> 
 <id>test-compile</id> 
<phase>test-compile</phase> 
 <goals> 
<goal>operation</goal> 
 </goals> 
 </execution> 
 <execution> 
<id>test</id> 
 <phase>test</phase> 
<goals> 
<goal>operation</goal> 
</goals> 
 </execution> 
 </executions> 
    <dependencies>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.13</version>
    </dependency>
    </dependencies>
    </plugin>
    </plugins>
    </build>
</project>

dbunit:operation我在命令行上运行 mvn 。

Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building my-app
[INFO]    task-segment: [dbunit:operation]
[INFO] ------------------------------------------------------------------------
[INFO] [dbunit:operation {execution: default-cli}]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Feb 10 23:02:41 PST 2011
[INFO] Final Memory: 6M/81M

它说构建成功。但是数据库中没有数据。

4

2 回答 2

4

在这里找到了答案

如果您的数据文件是平面格式 (FlatXmlDataSet),则添加平面将执行更新。

例如:这不起作用:

      <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>dbunit-maven-plugin</artifactId>
                    ...
            <executions>
                <execution>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>operation</goal>
                    </goals>
                    <configuration>
                        <type>CLEAN_INSERT</type>
                    <src>src/main/resources/opc1.xml</src>
                    </configuration>
                </execution>
            </executions>
        </plugin>

但这有效(至少它对我有用):

      <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>dbunit-maven-plugin</artifactId>
            <version>1.0-beta-3</version>
            <dependencies>
                <dependency>
                    <groupId>com.sybase</groupId>
                    <artifactId>jConnect</artifactId>
                    ...
            <executions>
                <execution>
                    <phase>test-compile</phase>
                    <goals>
                        <goal>operation</goal>
                    </goals>
                    <configuration>
                            <format>flat</format>
                        <type>CLEAN_INSERT</type>
                    <src>src/main/resources/opc1.xml</src>
                    </configuration>
                </execution>
            </executions>
        </plugin>
于 2012-04-12T08:20:16.947 回答
-1
  1. 在各自的用户中创建数据库(模式)。
  2. 您应该在项目中有适当的 XML 格式的属性文件。
  3. 转到项目并键入命令,例如 c:>project_name>mvn dbunit:operation。这将添加所有属性
于 2013-09-30T08:51:55.750 回答