Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

serveStatic - does not find resources from Jar. #24

Open
ThraaxSession opened this issue Aug 8, 2017 · 2 comments
Open

serveStatic - does not find resources from Jar. #24

ThraaxSession opened this issue Aug 8, 2017 · 2 comments

Comments

@ThraaxSession
Copy link

Hi @danneu

I've got following snippet:

val public = this::class.java.getResource("/public").path
val static =  serveStatic(public, maxAge = Duration.ofDays(365))

When I run it directly in gradle with ./gradlew run ... it works and I can gather the static files
But when I build a fat Jar and run it, it doesn't work.
Then I get this error:

WARN [serveStatic] Could not find public resource folder: "file:/home/gino/Programming/myapp/build/libs/myapp-SNAPSHOT.jar!/public". serveStatic skipped...

After unzipping the Jar, I can see that my public folder is there.

Do you have any ideas?

Thanks and best regards
Gino

@danneu
Copy link
Owner

danneu commented Aug 8, 2017

Yeah, I wasn't sure what the right way to do static asset lookup on the JVM.

The code for serveStatic is super simple: https://github.com/danneu/kog/blob/master/src/main/kotlin/com/danneu/kog/batteries/serveStatic.kt

I look for the public folder root via val publicRoot = File(publicFolderPath) and then assert that it's a folder.

Maybe there's a better solution than using File here?

Or maybe, for now, you can pass in a path that works with File(path) instead of "file:/home/gino/Programming/myapp/build/libs/myapp-SNAPSHOT.jar!/public"? Right now you do this::class.java.getResource("/public").path but maybe there's another method other than .path that can give a path that works with serveStatic, like .absolutePath or something.

I can't look it up right now.

@ThraaxSession
Copy link
Author

ThraaxSession commented Aug 9, 2017

Hmmm... I don't have an idea for it. But we can keep this issue up. And look for a better solution @danneu in future..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants