You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The workaround works, but it's not perfect, because yauaa fails to detect all resources on the classpath and fails back to the built-in list of resources (nice)
[2025/01/30 14:16:23.080] [main] INFO n.b.p.u.u.YauaaVersion: [] Yauaa 7.29.0 (v7.29.0 @ 2024-11-17T14:28:36Z)
[2025/01/30 14:16:23.080] [main] ERROR n.b.p.u.c.ConfigLoader: [] NO config files were found matching this expression: classpath*:UserAgents/**/*.yaml
[2025/01/30 14:16:23.080] [main] WARN n.b.p.u.c.ConfigLoader: [] Unable to load the default resources, usually caused by classloader problems.
[2025/01/30 14:16:23.080] [main] WARN n.b.p.u.c.ConfigLoader: [] Retrying with built in list.
[2025/01/30 14:16:24.474] [main] INFO n.c.b.s.b.y.YauaaBrowserInfoService: [] created yauaa user-agent analyzer in 1.394s
NOTE/WARNING: listing classpath in native-image is tricky:
resources-config.json patterns must look like this: your-folder.* if you want to list /your-folder/ in runtime, declaring separate files just doesn't work (tested with graalvm21)
classpath resources URIs in native image have URI scheme: resource:
just fyi, this is the code i'm using to list classpath directory content (took quite a lot trial and error iterations to make it work with regular classpath, uber-jars, jar-in-jars and native-image):
@JvmStatic
funlist(path:String): List<String> {
if (path.isBlank()) {
throwIllegalArgumentException("Can't list a blank path.")
}
val fsPath = asPath(path)
if (!Files.isDirectory(fsPath)) {
throwIOException("Not a directory: $path")
}
val origPath = path.replace("/+$".toRegex(), "")
val res =Files.list(fsPath)
.use { stream ->
stream
.map { origPath +"/"+ it.fileName.toString() }
.sorted()
.toList()
}
log.trace { "listed $path [fspath=$fsPath]: $res" }
return res
}
@JvmStatic
funasPath(path:String): Path {
val resUri =this.javaClass.getResource(path)?.toURI()
?:throwFileNotFoundException("Resource not found on classpath: $path")
val (prefix, cpPath) = splitCpPath(resUri.toString())
log.debug { "classpath path=`$path` uri=`$resUri`, prefix=`$prefix`, path=`$cpPath`" }
if (!(prefix.isEmpty() || prefix =="file")) {
val fs = getFileSystem(resUri)
log.debug { "filesystem for $resUri: $fs" }
}
returnPaths.get(resUri)
}
@JvmStatic
privatefungetFileSystem(uri:URI): FileSystem {
returntry {
FileSystems.getFileSystem(uri)
} catch (e:FileSystemNotFoundException) {
FileSystems.newFileSystem(uri, mapOf("create" to "true"))
}
}
@JvmStatic
privatefunsplitCpPath(path:String): Pair<String, String> {
val prefixes =listOf("file:", "jar:file:", "zip:file:", "resource:")
return prefixes.asSequence()
.filter { path.startsWith(it) }
.firstNotNullOfOrNull { Pair(it.substringBefore(":"), path.substringAfter(it)) }
?:Pair("", path)
}
The text was updated successfully, but these errors were encountered:
My experience with building a native executable is very limited at this time.
Do you have a minimal reproduction repository for me to better understand this?
native-image
compiled binary fails to initialize yauaa instance due to missing resourceslogs:
Workaround
I've added new file:
src/main/resources/META-INF/native-image/yauaa/yauaa/resource-config.json
with the following contentThe workaround works, but it's not perfect, because yauaa fails to detect all resources on the classpath and fails back to the built-in list of resources (nice)
NOTE/WARNING: listing classpath in native-image is tricky:
your-folder.*
if you want to list/your-folder/
in runtime, declaring separate files just doesn't work (tested with graalvm21)resource:
just fyi, this is the code i'm using to list classpath directory content (took quite a lot trial and error iterations to make it work with regular classpath, uber-jars, jar-in-jars and native-image):
The text was updated successfully, but these errors were encountered: