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

Universal App - Can't find resources #899

Closed
robgraeber opened this issue Oct 21, 2016 · 2 comments
Closed

Universal App - Can't find resources #899

robgraeber opened this issue Oct 21, 2016 · 2 comments

Comments

@robgraeber
Copy link

Hey I'm having issues getting access to resource files after packaging. It seems like getResource can't find the root of the Jar for some reason.

For example, before packaging:

getClass.getResource("/").getPath -> /Users/****/example-proj/target/scala-2.11/classes/
getClass.getResource("").getPath -> /Users/****/example-proj/target/scala-2.11/classes/com/example/foo/
getClass.getClassLoader.getResource("/").getPath -> java.lang.NullPointerException
getClass.getClassLoader.getResource("").getPath -> /Users/****/example-proj/target/scala-2.11/classes/

And after packaging:

getClass.getResource("/").getPath -> java.lang.NullPointerException
getClass.getResource("").getPath -> file:/Users/****/example-proj/target/universal/stage/lib/default.example-proj-1.0.jar!/com/example/foo/
getClass.getClassLoader.getResource("/").getPath -> java.lang.NullPointerException
getClass.getClassLoader.getResource("").getPath -> java.lang.NullPointerException

I opened up the example-proj-1.0.jar and all the resources are there. Is there something I'm missing? I read some stack overflow threads about maybe adding Class-Path: . to the manifest.mf.

@robgraeber robgraeber changed the title Universal App - Jar classpath for resources Universal App - Can't find resources Oct 21, 2016
@muuki88
Copy link
Contributor

muuki88 commented Oct 22, 2016

I guess you resolved this on your own. This is not related to native-packager, but the java NIO Path implementation.

@robgraeber
Copy link
Author

Yeah I figured it out. It was because I was iterating over the files in a directory, but that doesn't work with JARs. I ended up writing a helper function that checks if the code is inside of a JAR or not, and iterates appropriately.

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