从 Maven 启动 H2 数据库服务器?

发布于 2024-08-20 07:25:38 字数 236 浏览 8 评论 0原文

假设我想创建并使用 H2 数据库进行集成测试。

Maven 有一个运行测试的命令:mvn test

有没有办法告诉maven启动H2数据库服务器进行测试并在完成后停止它?

我想这与我通过 Maven 命令运行 tomcat 的方式类似 (mvn tomcat:run)。

抱歉,如果这个问题毫无意义,我仍在思考新概念。

Suppose I want to create and use an H2 database for my integration tests.

Maven has a command to run tests: mvn test.

Is there a way to tell maven to start an H2 database server for the tests and stop it when it's done?

I imagine this working similar to how I can run tomcat via a Maven command (mvn tomcat:run).

Sorry if this question is nonsensical, I'm still wrapping my head around new concepts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

旧人 2024-08-27 07:25:38

我能够在不使用外部服务器的情况下让它工作,只需通过 Maven 添加对 H2 的依赖,然后使用这个 bean:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.h2.Driver"/>
    <property name="url" value="jdbc:h2:file:h2\db"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>        
</bean>

话又说回来,这要求我使用基于文件的数据库而不是内存中的数据库。但它确实有效。

I was able to get it to work without using an external server just by adding the dependency to H2 via Maven and then using this bean:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.h2.Driver"/>
    <property name="url" value="jdbc:h2:file:h2\db"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>        
</bean>

Then again, this required that I use a file-based DB instead of in-memory. But it does the trick.

时光磨忆 2024-08-27 07:25:38

您可以使用启动和停止数据库的主要方法创建 2 个小类。这个想法是在运行集成测试之前运行 StartServer 类,然后在测试运行后运行 StopServer 类。

您应该按照 本文档 (描述用于在集成测试中启动和停止 Jetty)

在 pom.xml 中,您应该定义 maven-exec-plugin 来运行 exec:java 目标并创建 2 个执行(1 个用于调用 StartServer,1 个用于 StopServer):

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.1.1</version>
  <executions>
    <execution>
      <!-- start server before integration tests -->
      <id>start</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>java</goal>
      </goals>
      <configuration>
        <mainClass>com.foo.StartServer</mainClass>
      </configuration>
     </execution>
     <execution>
      <!-- stop server after integration tests -->
      <id>stop</id>
      <phase>post-integration-test</phase>
      <goals>
        <goal>java</goal>
      </goals>
      <configuration>
        <mainClass>com.foo.StopServer</mainClass>
      </configuration>
     </execution>
   </executions>
 </plugin>

希望这就是您想要的

you can create 2 small classes with main methods that start and stop the database. the idea is to run the StartServer class before the integration tests are run and then class StopServer after the tests have run.

you should do the same for your DB server as described somewhere in this document (description is for starting and stopping Jetty in integration tests)

in your pom.xml you should define the maven-exec-plugin to run the exec:java goal and create 2 executions (1 for calling StartServer and 1 for StopServer):

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.1.1</version>
  <executions>
    <execution>
      <!-- start server before integration tests -->
      <id>start</id>
      <phase>pre-integration-test</phase>
      <goals>
        <goal>java</goal>
      </goals>
      <configuration>
        <mainClass>com.foo.StartServer</mainClass>
      </configuration>
     </execution>
     <execution>
      <!-- stop server after integration tests -->
      <id>stop</id>
      <phase>post-integration-test</phase>
      <goals>
        <goal>java</goal>
      </goals>
      <configuration>
        <mainClass>com.foo.StopServer</mainClass>
      </configuration>
     </execution>
   </executions>
 </plugin>

hope that's what you want

匿名的好友 2024-08-27 07:25:38

该插件可以很好地在集成测试(默认插件阶段)之前生成一个具有 tcp 模式的新 H2 DB: github 上的 h2-maven-plugin

它没有很好的文档记录,但您可以检查 Mojo 源代码以了解配置选项。它发布在 Maven Central 上。


基本上,对于集成测试,您可能希望 Maven:

  • 为 Tomcat 服务器和 H2 保留随机可用的网络端口(以避免端口冲突)
  • 启动 H2 服务器
  • 启动 Tomcat 服务器
  • 运行集成测试
  • 停止 Tomcat 服务器
  • 停止 H2 服务器

这可以通过如下所示的 Maven 配置来实现。
假设您的集成测试使用自定义接口 JUnit 类别进行注释:

@Category(IntegrationTest.class)

此 Maven 配置对我来说效果很好:

<profile>
   <id>it</id>
   <build>
     <plugins>

       <!-- Reserve randomly available network ports -->
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>build-helper-maven-plugin</artifactId>
         <executions>
           <execution>
             <id>reserve-network-port</id>
             <goals>
               <goal>reserve-network-port</goal>
             </goals>
             <phase>process-resources</phase>
             <configuration>
               <portNames>
                 <portName>tomcat.test.http.port</portName>
                 <portName>h2.test.tcp.port</portName>
               </portNames>
             </configuration>
           </execution>
         </executions>
       </plugin>


       <!-- Start H2 before integration tests, accepting tcp connections on the randomly selected port -->
       <plugin>
         <groupId>com.edugility</groupId>
         <artifactId>h2-maven-plugin</artifactId>
         <version>1.0</version>
         <configuration>
           <port>${h2.test.tcp.port}</port>
         </configuration>
         <executions>
             <execution>
               <id>Spawn a new H2 TCP server</id>
               <goals>
                 <goal>spawn</goal>
               </goals>
             </execution>
             <execution>
               <id>Stop a spawned H2 TCP server</id>
               <goals>
                 <goal>stop</goal>
               </goals>
             </execution>
           </executions>
       </plugin>


       <!-- Start Tomcat before integration tests on the -->
       <plugin>
         <groupId>org.apache.tomcat.maven</groupId>
         <artifactId>tomcat7-maven-plugin</artifactId>
         <configuration>
           <systemProperties>
             <spring.profiles.active>integration_tests</spring.profiles.active>
             <httpPort>${http.test.http.port}</httpPort>
             <h2Port>${h2.test.tcp.port}</h2Port>
           </systemProperties>
           <port>${http.test.http.port}</port>
           <contextFile>src/main/java/META-INF/tomcat/webapp-test-context-using-h2.xml</contextFile>
           <fork>true</fork>
         </configuration>
         <executions>
           <execution>
             <id>run-tomcat</id>
             <phase>pre-integration-test</phase>
             <goals>
               <goal>run</goal>
             </goals>
           </execution>
           <execution>
             <id>stop-tomcat</id>
             <phase>post-integration-test</phase>
             <goals>
               <goal>shutdown</goal>
             </goals>
           </execution>
         </executions>
         <dependencies>
           <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
             <version>${mysql.version}</version>
           </dependency>
           <dependency>
             <groupId>com.h2database</groupId>
             <artifactId>h2</artifactId>
             <version>${h2.version}</version>
           </dependency>
         </dependencies>
       </plugin>


       <!-- Run the integration tests annotated with @Category(IntegrationTest.class) -->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-failsafe-plugin</artifactId>
         <!-- Bug in 2.12.x -->
         <version>2.11</version>
         <dependencies>
           <dependency>
             <groupId>org.apache.maven.surefire</groupId>
             <artifactId>surefire-junit47</artifactId>
             <version>2.12.4</version>
           </dependency>
         </dependencies>
         <configuration>
           <groups>com.mycompany.junit.IntegrationTest</groups>
           <failIfNoTests>false</failIfNoTests>
           <junitArtifactName>junit:junit-dep</junitArtifactName>
           <systemPropertyVariables>
             <httpPort>${tomcat.test.http.port}</httpPort>
             <h2Port>${h2.test.tcp.port}</h2Port>
           </systemPropertyVariables>
         </configuration>
         <executions>
           <execution>
             <goals>
               <goal>integration-test</goal>
             </goals>
           </execution>
         </executions>
       </plugin>

     </plugins>
   </build>
 </profile>

您可能希望在 tomcat 上下文文件上使用 Maven 过滤器,以便替换端口:

   <contextFile>src/main/java/META-INF/tomcat/webapp-test-context-using-h2.xml</contextFile>

文件内容为:

  <Resource name="jdbc/dataSource"
            auth="Container"
            type="javax.sql.DataSource"
            maxActive="100"
            maxIdle="30"
            maxWait="10000"
            username=""
            password=""
            driverClassName="org.h2.Driver"
            url="jdbc:h2:tcp://localhost:${h2.test.tcp.port}/mem:db;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL"/>

或者如果您不这样做不需要 JNDI 数据源,您可以使用 Spring 声明的数据源,使用相同的属性...


如果您希望能够设置集成测试 tomcat,并从 IDE 运行集成测试,则需要额外一趟:

您可以使用属性来分叉或不分叉 Tomcat 服务器:

<fork>${integrationTestsForkTomcatJvm}</fork>

当您设置 fork=false 时,服务器将阻塞并且 Maven 将不会继续,因此集成测试将不会运行,但您将能够从您的IDE。

This plugin works fine to spawn a new H2 DB with tcp mode before integration tests (the default plugin phase): h2-maven-plugin on github

It is not well documented but you can check the Mojo sources to know the configuration options. It is published on maven central.


Basically, for integration tests, you may want Maven to:

  • Reserve randomly available network ports, for your Tomcat server, and your H2 (to avoid port conflicts)
  • Start the H2 server
  • Start the Tomcat server
  • Run integration tests
  • Stop the Tomcat server
  • Stop the H2 server

This can be achieved with a Maven configuration looking like this.
Assuming your integration tests are annoted with a custom interface JUnit Category:

@Category(IntegrationTest.class)

This Maven configuration works fine for me:

<profile>
   <id>it</id>
   <build>
     <plugins>

       <!-- Reserve randomly available network ports -->
       <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>build-helper-maven-plugin</artifactId>
         <executions>
           <execution>
             <id>reserve-network-port</id>
             <goals>
               <goal>reserve-network-port</goal>
             </goals>
             <phase>process-resources</phase>
             <configuration>
               <portNames>
                 <portName>tomcat.test.http.port</portName>
                 <portName>h2.test.tcp.port</portName>
               </portNames>
             </configuration>
           </execution>
         </executions>
       </plugin>


       <!-- Start H2 before integration tests, accepting tcp connections on the randomly selected port -->
       <plugin>
         <groupId>com.edugility</groupId>
         <artifactId>h2-maven-plugin</artifactId>
         <version>1.0</version>
         <configuration>
           <port>${h2.test.tcp.port}</port>
         </configuration>
         <executions>
             <execution>
               <id>Spawn a new H2 TCP server</id>
               <goals>
                 <goal>spawn</goal>
               </goals>
             </execution>
             <execution>
               <id>Stop a spawned H2 TCP server</id>
               <goals>
                 <goal>stop</goal>
               </goals>
             </execution>
           </executions>
       </plugin>


       <!-- Start Tomcat before integration tests on the -->
       <plugin>
         <groupId>org.apache.tomcat.maven</groupId>
         <artifactId>tomcat7-maven-plugin</artifactId>
         <configuration>
           <systemProperties>
             <spring.profiles.active>integration_tests</spring.profiles.active>
             <httpPort>${http.test.http.port}</httpPort>
             <h2Port>${h2.test.tcp.port}</h2Port>
           </systemProperties>
           <port>${http.test.http.port}</port>
           <contextFile>src/main/java/META-INF/tomcat/webapp-test-context-using-h2.xml</contextFile>
           <fork>true</fork>
         </configuration>
         <executions>
           <execution>
             <id>run-tomcat</id>
             <phase>pre-integration-test</phase>
             <goals>
               <goal>run</goal>
             </goals>
           </execution>
           <execution>
             <id>stop-tomcat</id>
             <phase>post-integration-test</phase>
             <goals>
               <goal>shutdown</goal>
             </goals>
           </execution>
         </executions>
         <dependencies>
           <dependency>
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
             <version>${mysql.version}</version>
           </dependency>
           <dependency>
             <groupId>com.h2database</groupId>
             <artifactId>h2</artifactId>
             <version>${h2.version}</version>
           </dependency>
         </dependencies>
       </plugin>


       <!-- Run the integration tests annotated with @Category(IntegrationTest.class) -->
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-failsafe-plugin</artifactId>
         <!-- Bug in 2.12.x -->
         <version>2.11</version>
         <dependencies>
           <dependency>
             <groupId>org.apache.maven.surefire</groupId>
             <artifactId>surefire-junit47</artifactId>
             <version>2.12.4</version>
           </dependency>
         </dependencies>
         <configuration>
           <groups>com.mycompany.junit.IntegrationTest</groups>
           <failIfNoTests>false</failIfNoTests>
           <junitArtifactName>junit:junit-dep</junitArtifactName>
           <systemPropertyVariables>
             <httpPort>${tomcat.test.http.port}</httpPort>
             <h2Port>${h2.test.tcp.port}</h2Port>
           </systemPropertyVariables>
         </configuration>
         <executions>
           <execution>
             <goals>
               <goal>integration-test</goal>
             </goals>
           </execution>
         </executions>
       </plugin>

     </plugins>
   </build>
 </profile>

You may want to use maven filters on the tomcat context file so that the port is replaced:

   <contextFile>src/main/java/META-INF/tomcat/webapp-test-context-using-h2.xml</contextFile>

With the file content being:

  <Resource name="jdbc/dataSource"
            auth="Container"
            type="javax.sql.DataSource"
            maxActive="100"
            maxIdle="30"
            maxWait="10000"
            username=""
            password=""
            driverClassName="org.h2.Driver"
            url="jdbc:h2:tcp://localhost:${h2.test.tcp.port}/mem:db;DB_CLOSE_ON_EXIT=FALSE;MODE=MySQL"/>

Or if you don't want a JNDI datasource, you can use a Spring declared dataSource, using the the same property...


One extra trip if you want to be able to setup your integration tests tomcat, and run the integration tests from your IDE:

You can use use a property to fork or not the Tomcat server:

<fork>${integrationTestsForkTomcatJvm}</fork>

When you set fork=false, the server will block and maven won't continue, so the integration tests won't be run, but you will be able to run them from your ide.

许一世地老天荒 2024-08-27 07:25:38

在运行单元测试之前,我创建了一个基于文件的 H2 数据库。该文件位于 target 目录中,可以随时使用 mvn clean 删除。

我使用 maven-sql-plugin 如下:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>sql-maven-plugin</artifactId>
  <version>1.5</version>
  <dependencies>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId> 
      <version>1.3.166</version>
    </dependency>
  </dependencies>
  <configuration>
    <driver>org.h2.Driver</driver>
    <url>jdbc:h2:file:target/db/testdb</url>
    <username>sa</username>
    <password></password>
    <autocommit>true</autocommit>
    <skip>${maven.test.skip}</skip>
  </configuration>
  <executions>
    <execution>
      <id>create-db</id>
      <phase>process-test-resources</phase>
      <goals>
        <goal>execute</goal>
      </goals>
      <configuration>
        <srcFiles>
          <srcFile>${sql.dir}/drop_db.sql</srcFile>
          <srcFile>${sql.dir}/tables.sql</srcFile>
          <srcFile>${sql.dir}/constraints.sql</srcFile>
          ... etc ...
        </srcFiles>
      </configuration>
    </execution>
  </executions>
</plugin>

可以通过运行 mvn process-test-resources 来创建数据库。运行测试时,请确保通过 hibernate 属性连接到 target/db/testdb 中的数据库。

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
      destroy-method="close"
      p:driverClassName="org.h2.Driver"
      p:url="jdbc:h2:file:target/db/testdb"
      p:username="sa"
      p:password="" />

您还需要在 maven 的依赖项中依赖 com.h2database.h2。

I create a file-based H2 database before unit tests are run. The file lives in the target directory and can be removed at any time using mvn clean.

I use the maven-sql-plugin as follows:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>sql-maven-plugin</artifactId>
  <version>1.5</version>
  <dependencies>
    <dependency>
      <groupId>com.h2database</groupId>
      <artifactId>h2</artifactId> 
      <version>1.3.166</version>
    </dependency>
  </dependencies>
  <configuration>
    <driver>org.h2.Driver</driver>
    <url>jdbc:h2:file:target/db/testdb</url>
    <username>sa</username>
    <password></password>
    <autocommit>true</autocommit>
    <skip>${maven.test.skip}</skip>
  </configuration>
  <executions>
    <execution>
      <id>create-db</id>
      <phase>process-test-resources</phase>
      <goals>
        <goal>execute</goal>
      </goals>
      <configuration>
        <srcFiles>
          <srcFile>${sql.dir}/drop_db.sql</srcFile>
          <srcFile>${sql.dir}/tables.sql</srcFile>
          <srcFile>${sql.dir}/constraints.sql</srcFile>
          ... etc ...
        </srcFiles>
      </configuration>
    </execution>
  </executions>
</plugin>

The database can be created by running mvn process-test-resources. When tests are run, make sure you connect to the database in target/db/testdb via hibernate properties.

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" 
      destroy-method="close"
      p:driverClassName="org.h2.Driver"
      p:url="jdbc:h2:file:target/db/testdb"
      p:username="sa"
      p:password="" />

You will also need to a dependency on com.h2database.h2 in maven's dependencies.

月亮坠入山谷 2024-08-27 07:25:38

在我的项目中,为了进行单元测试,我要求 Spring 处理数据库创建和初始化。正如H2文档中所述,您可以为此创建一个bean:

<bean id = "org.h2.tools.Server"
    class="org.h2.tools.Server"
    factory-method="createTcpServer"
    init-method="start"
    destroy-method="stop">
    <constructor-arg value="-tcp,-tcpAllowOthers,true,-tcpPort,8043" />
</bean>

您只需当您开始单元测试时,需要使用此配置启动 Spring 上下文。

In my project, for unit testing, I asked Spring to handle this database creation and initialization. As stated in the H2 documentation, you can create a bean for that:

<bean id = "org.h2.tools.Server"
    class="org.h2.tools.Server"
    factory-method="createTcpServer"
    init-method="start"
    destroy-method="stop">
    <constructor-arg value="-tcp,-tcpAllowOthers,true,-tcpPort,8043" />
</bean>

You simply need to start the Spring context with this configuration when you start your unit tests.

秋日私语 2024-08-27 07:25:38

我刚刚开始为 maven @ bitbucket 开发 H2 插件项目。我将不胜感激任何帮助。

希望它会 有帮助。

I've just started project for H2 plugin for maven @ bitbucket. I will appreciate any help with it.

https://bitbucket.org/dohque/maven-h2-plugin

Hope it will be helpful.

魔法唧唧 2024-08-27 07:25:38

如果您想将其保存在内存中,则只需使用不同的 URL:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.h2.Driver"/>
    <property name="url" value="jdbc:h2:mem:db"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>        
</bean>

您可以提供其他选项,例如: ;DB_CLOSE_DELAY=-1

参见: http://www.h2database.com/html/features.html#in_memory_databases

If you want to make it in memory, then just use a different URL:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.h2.Driver"/>
    <property name="url" value="jdbc:h2:mem:db"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>        
</bean>

You can give additional options, such as: ;DB_CLOSE_DELAY=-1

see: http://www.h2database.com/html/features.html#in_memory_databases

谁的年少不轻狂 2024-08-27 07:25:38

以下工作适合我(仅使用 h2 依赖项和 exec-maven-plugin):

    <build>
        <plugins>
            <!-- start/stop H2 DB as a server -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>start-h2</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>org.h2.tools.Server</mainClass>
                            <arguments>
                                <argument>-tcp</argument>
                                <argument>-tcpDaemon</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-h2</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>org.h2.tools.Server</mainClass>
                            <arguments>
                                <argument>-tcpShutdown</argument>
                                <argument>tcp://localhost:9092</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <includeProjectDependencies>true</includeProjectDependencies>
                    <includePluginDependencies>true</includePluginDependencies>
                    <executableDependency>
                        <groupId>com.h2database</groupId>
                        <artifactId>h2</artifactId>
                    </executableDependency>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.h2database</groupId>
                        <artifactId>h2</artifactId>
                        <version>1.3.173</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
</build>

请注意,在我的 pom.xmlcom.h2database:h2 不是项目依赖项。
如果您拥有它,您可能不需要将其显式命名为插件依赖项。

following does the job for me (just using h2 dependency and the exec-maven-plugin):

    <build>
        <plugins>
            <!-- start/stop H2 DB as a server -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.2.1</version>
                <executions>
                    <execution>
                        <id>start-h2</id>
                        <phase>pre-integration-test</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>org.h2.tools.Server</mainClass>
                            <arguments>
                                <argument>-tcp</argument>
                                <argument>-tcpDaemon</argument>
                            </arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>stop-h2</id>
                        <phase>post-integration-test</phase>
                        <goals>
                            <goal>java</goal>
                        </goals>
                        <configuration>
                            <mainClass>org.h2.tools.Server</mainClass>
                            <arguments>
                                <argument>-tcpShutdown</argument>
                                <argument>tcp://localhost:9092</argument>
                            </arguments>
                        </configuration>
                    </execution>
                </executions>
                <configuration>
                    <includeProjectDependencies>true</includeProjectDependencies>
                    <includePluginDependencies>true</includePluginDependencies>
                    <executableDependency>
                        <groupId>com.h2database</groupId>
                        <artifactId>h2</artifactId>
                    </executableDependency>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>com.h2database</groupId>
                        <artifactId>h2</artifactId>
                        <version>1.3.173</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
</build>

please note, in my pom.xml the com.h2database:h2 was not project dependency.
In case you'd have it you might don't need to explicitly name it as a plugin dependency.

唔猫 2024-08-27 07:25:38

由于 H2 不提供 Maven 插件,您应该使用 maven-antrun-plugin 启动它。在 ant 任务中编写启动和停止 h2 引擎的代码,并在集成测试启动和停止时调用它。

请参阅 http://docs.codehaus.org/display/MAVENUSER 的详细信息/Maven+和+集成+测试

Since H2 doesn't provide Maven plugin you should start it using maven-antrun-plugin. Write code for start and stop h2 engine in ant task and call it when your integration test starts and stop.

See details on http://docs.codehaus.org/display/MAVENUSER/Maven+and+Integration+Testing

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文