2013-04-15 221 views
6

錯誤: [錯誤] com.googlecode.flyway.core.api.FlywayException:無法確定類路徑位置的URL:db/migration(ClassLoader:ClassRealm [plugin> com.googlecode.flyway:flyway-maven-plugin:2.1.1,parent:[email protected]])Flyway未在數據庫/遷移中找到我的sql遷移

我跟着快速入門,所以我沒有真正做任何複雜的事情。

的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.cpt.migrations</groupId> 
    <artifactId>cpt_migrations</artifactId> 
    <version>1.0-SNAPSHOT</version> 
    <packaging>jar</packaging> 

    <name>cpt_migrations</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> 
    <dependency> 
     <groupId>mysql</groupId> 
     <artifactId>mysql-connector-java</artifactId> 
     <version>5.1.24</version> 
    </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>com.googlecode.flyway</groupId> 
       <artifactId>flyway-maven-plugin</artifactId> 
       <version>2.1.1</version> 
       <configuration> 
        <user>root</user> 
        <password></password> 
        <driver>com.mysql.jdbc.Driver</driver> 
        <url>jdbc:mysql://localhost:3306/cpt</url> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

我的文件夾結構規定PROJECT_ROOT/src目錄/主/資源/ DB /遷移/ V1__Base_version.sql:

我得到的錯誤時,從PROJECT_ROOT,我執行: mvn flyway:migrate

回答

13

不要忘記首先調用compile,以確保資源被複制。

+2

啊......謝謝阿克塞爾。 maven noob失敗。 –

+0

你是什麼意思?你能解釋得更好嗎? 我使用netbeans 7.4 –

+0

@Axel方丹像傑夫我已經配置我的pom.xml,我有我的.sql腳本在db/migration文件夾下的資源..執行編譯通道:migrate我得到com.googlecode.flyway .core.api.FlywayException:無法創建模式'':不正確的數據庫名''可能是什麼問題?我的SQL文件名是test.sql –

0

它必須被編譯:

mvn compile flyway:migrate 

您可以使用

<executions> 
      <execution> 
      <id>compile</id> 
      <phase>compile</phase> 
      <goals> 
       <goal>migrate</goal> 
      </goals> 
      </execution> 
      <execution> 
      <id>clean</id> 
      <phase>clean</phase> 
      <goals> 
       <goal>clean</goal> 
      </goals> 
      </execution> 
     </executions> 

<plugin>..</plugin> 

,然後需要遷移任務

+3

我不認爲在編譯上執行遷移是個好主意。 –

0
的執行只是MVN編譯

執行mvn來自目標目錄所在目錄的命令。

1

在我而言,我不得不在我的application.properties(春季啓動)明確地設置

flyway.locations=classpath:db/migration 

爲它工作。

+0

設置在哪裏?不要以爲每個人都是這些東西的專家! – Willa

+0

@Willa在Spring Boot的application.properties文件中。我更新答案 – ianaz