[英]FlyWayDB - Unable to resolve location classpath
i have problem to setting location with the classpath in FLyway, when I use with the filesystem its working properly.我在 FLyway 中使用类路径设置位置时遇到问题,当我使用文件系统时它工作正常。
Example:例子:
This working: this.setLocations("filesystem:C:\\Projects\\ProjectName\\src\\main\\java\\com\\some1\\some2\\some3\\database\\migration");
这个工作: this.setLocations("filesystem:C:\\Projects\\ProjectName\\src\\main\\java\\com\\some1\\some2\\some3\\database\\migration");
This NOT working(I try delimiters: "\", ".", "/"): this.setLocations("classpath:ProjectName/src/main/java/com/some1/some2/some3/database/migration");
这不起作用(我尝试分隔符:“\”、“.”、“/”): this.setLocations("classpath:ProjectName/src/main/java/com/some1/some2/some3/database/migration");
When not working, its throwing error:当不工作时,它的抛出错误:
[WARNING] [] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] [tid: _ThreadID=19 _ThreadName=RunLevelControllerThread-xx] [timeMillis: 1495044249009] [levelValue: 900] [[ Unable to resolve location classpath: ProjectName/src/main/java/com/some1/some2/some3/database/migration]] [警告] [] [org.flywaydb.core.internal.util.scanner.classpath.ClassPathScanner] [tid: _ThreadID=19 _ThreadName=RunLevelControllerThread-xx] [timeMillis: 1495044249009] [levelValue: 900] [[无法解析位置类路径:ProjectName/src/main/java/com/some1/some2/some3/database/migration]]
I try some delimiters as above, without key word "classpath", and always when I want to use classpath its throwing "Unable to resolve location...".我尝试了一些如上所述的定界符,没有关键字“类路径”,并且总是在我想使用类路径时抛出“无法解析位置...”。
I use flyway ver 4.1.2 and by JavaAPI( https://flywaydb.org/getstarted/firststeps/api )我使用 flyway ver 4.1.2 和 JavaAPI ( https://flywaydb.org/getstarted/firststeps/api )
edit./ When I change location of migrating sql files and name of directory on default for Flyway, and not setting location, its working fine.编辑./ 当我更改迁移 sql 文件的位置和 Flyway 的默认目录名称,而不是设置位置时,它工作正常。 So, conclusion is that I wrong wrote the classpath, but what i do wrong?所以,结论是我写错了类路径,但我做错了什么?
Default configuration: 1. main/resources/ db / migration < default folder for sql files to migrate 2. not setting location默认配置: 1. main/resources/ db / migration < default folder for sql files to migrate 2. not setting location
Some suggestion?一些建议?
'classpath' means really classpath and you can not extend your classpath with a path. 'classpath' 意味着真正的类路径,你不能用路径扩展你的类路径。
When I see your classpath declaration than I think your migration will be packaged in a jar with the path ' com/some1/some2/some3/database/migration
'当我看到您的类路径声明时,我认为您的迁移将被打包在一个路径为“ com/some1/some2/some3/database/migration
”的 jar 中
=> so your classpath configuration must be look like: => 所以你的类路径配置必须是这样的:
classpath:com/some1/some2/some3/database/migration
If you use SQL file based migration I have better experience with src/main/resources
as base location.如果您使用基于 SQL 文件的迁移,我对src/main/resources
作为基本位置有更好的体验。
I struggled with the same problem for a couple of days.我在同样的问题上挣扎了几天。 What finally helped me was to modify pom.xml
, so that <build>
node lists all locations with property files:最终帮助我的是修改pom.xml
,以便<build>
节点列出所有带有属性文件的位置:
<project...>
...
<build>
<resources>
...
<resource>
<directory>src/main/resources</directory>
<includes>
<include>*.*</include>
<include>sql/migration/*</include>
</includes>
</resource>
</resources>
</build>
</project>
Instead of creation complete package for DB migrate scripts, suggested to create a folder at java build path Project -> Properties -> SourceTab -> AddFolder
it takes the scripts to classpath with the desired folder name and keeps that name into your JavaClass建议在 java 构建路径Project -> Properties -> SourceTab -> AddFolder
创建一个文件夹,而不是为 DB 迁移脚本创建完整的包,它将脚本带到具有所需文件夹名称的类路径,并将该名称保留到您的 JavaClass 中
"classpath:foldername" “类路径:文件夹名”
For meu the resources at pom.xl answer given by @Tinki was what resolved my case对于 meu,@Tinki 给出的 pom.xl 答案中的资源解决了我的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.