2013-04-15 220 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