У меня есть проект maven-flyway, который просто заполнен сценариями sql для запуска. Вот моя структура каталогов для этого проекта:
src/
├── main/
└── java/
└── callbacks/
├── FooCallback.java
└── resources/
└── db/
├── Script1.sql
├── Script2.sql
├── Script3.sql
└── ...
Вот свойства в моем pom.xml
:
<properties>
<java.version>1.8</java.version>
<maven.flyway.version>5.0.6</maven.flyway.version>
<flyway.callbacks>main.java.callbacks.FooCallbback</flyway.callbacks>
<flyway.outOfOrder>true</flyway.outOfOrder>
<url>...</url>
<user>...</user>
<password>...</password>
<locations>db</locations>
</properties>
Но каждый раз, когда я запускаю flyway:migrate
, я получаю следующую ошибку:
[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:4.0.3:migrate (default-cli) on project database: org.flywaydb.core.api.FlywayException: Unable to instantiate class: main.java.callbacks.FooCallback -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.flywaydb:flyway-maven-plugin:4.0.3:migrate (default-cli) on project database: org.flywaydb.core.api.FlywayException: Unable to instantiate class: main.java.callbacks.FooCallback
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
at org.codehaus.classworlds.Launcher.main(Launcher.java:47)
Caused by: org.apache.maven.plugin.MojoExecutionException: org.flywaydb.core.api.FlywayException: Unable to instantiate class: main.java.callbacks.FooCallback
at org.flywaydb.maven.AbstractFlywayMojo.execute(AbstractFlywayMojo.java:541)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
... 21 more
Caused by: java.lang.ClassNotFoundException: main.java.callbacks.FooCallback
at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.flywaydb.core.internal.util.ClassUtils.instantiate(ClassUtils.java:49)
at org.flywaydb.core.internal.util.ClassUtils.instantiateAll(ClassUtils.java:65)
at org.flywaydb.core.Flyway.setCallbacksAsClassNames(Flyway.java:867)
at org.flywaydb.core.Flyway.configure(Flyway.java:1263)
at org.flywaydb.maven.AbstractFlywayMojo.execute(AbstractFlywayMojo.java:537)
... 23 more
Очевидно, что структура моей папки несколько испорчена. Я попытался изменить структуру папок на:
src/
├── main/
└── resources/
└── db/
└── callbacks/
├── FooCallback.java
├── Script1.sql
├── Script2.sql
├── Script3.sql
└── ...
И мои свойства пом:
<flyway.callbacks>db.callbacks.FooCallback</flyway.callbacks>
Но я все еще получаю ту же ошибку. Как заставить это работать без проблем?