pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<configuration>
<target>
<property file="src/main/resources/application.properties" />
<sql driver="${jdbc.driver}" url="${jdbc.url}" userid="${jdbc.username}" password="${jdbc.password}"
onerror="abort" failOnConnectionError="true" encoding="${project.build.sourceEncoding}">
<classpath refid="maven.test.classpath" />
<transaction src="src/main/resources/script/schema-h2.sql"/>
<transaction src="src/main/resources/script/data-h2.sql"/>
</sql>
</target>
</configuration>
</plugin>
application.properties
#h2 database settings
jdbc.driver=org.h2.Driver
jdbc.url=jdbc:h2:file:~/.h2/mybatis-study;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1
#jdbc.url=jdbc:h2:mem:mybatis-study;AUTO_SERVER=TRUE;DB_CLOSE_DELAY=-1
jdbc.username=sa
jdbc.password=
运行
mvn antrun:run