配置pom.propertis即可
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>properties-maven-plugin</artifactId> <version>1.0-alpha-2</version> <executions> <execution> <phase>initialize</phase> <goals> <goal>read-project-properties</goal> </goals> <configuration> <files> <file>${project.basedir}/src/main/resources/jdbc.properties</file> </files> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>sql-maven-plugin</artifactId> <version>1.5</version> <dependencies> <!-- 定義依賴的資料庫驅動jar包(mysql) --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>${mysql.version}</version> </dependency> </dependencies> <configuration> <!-- 定義資料庫連線引數 --> <driver>${jdbc.driverClassName}</driver> <url>${jdbc.url}</url> <username>${jdbc.username}</username> <password>${jdbc.password}</password> <!-- 指定要執行的sql指令碼 'sql'資料夾為指令碼所在資料夾下的子資料夾 --> <srcFiles> <srcFile>${project.basedir}/sql/emms-dict.sql</srcFile> </srcFiles> </configuration> <executions> <execution> <phase>compile</phase> <goals> <goal>execute</goal> </goals> </execution> </executions> </plugin>
解釋:第一個外掛為載入你的配置檔案的外掛,
第二個為執行sql檔案的外掛