<build> <finalName>buglife-data-access</finalName> <plugins> <!--添加sql-maven-plugin插件--> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sql-maven-plugin</artifactId> <version>1.5</version> <!---由於該實例中用到的數據庫是mysql,故需依賴於mysql鏈接驅動--> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.27</version> </dependency> </dependencies> <!--爲該插件配置數據庫鏈接信息--> <configuration> <driver>com.mysql.jdbc.Driver</driver> <url>jdbc:mysql://localhost:3306</url> <username>root</username> <password>root</password> </configuration> <executions> <!--建立數據庫--> <execution> <id>create-db</id> <phase>process-test-resources</phase> <goals> <goal>execute</goal> </goals> <configuration> <!--設置自動提交事務--> <autocommit>true</autocommit> <srcFiles> <srcFile>src/main/resources/create_db.sql</srcFile> </srcFiles> </configuration> </execution> <!--建立數據表--> <execution> <id>create-table</id> <phase>process-test-resources</phase> <goals> <goal>execute</goal> </goals> <configuration> <autocommit>true</autocommit> <srcFiles> <srcFile>src/main/resources/create_table.sql</srcFile> </srcFiles> </configuration> </execution> <!--插入數據--> <execution> <id>insert-data</id> <phase>process-test-resources</phase> <goals> <goal>execute</goal> </goals> <configuration> <orderFile>ascending</orderFile> <fileset> <basedir>${basedir}</basedir> <includes> <include>src/main/resources/init_data.sql</include> </includes> </fileset> </configuration> </execution> </executions> </plugin> </plugins> </build>