Jump to content

[1.16.5] Cannot find resource in final JAR.


theredwagoneer

Recommended Posts

I am attempting to use the javax-usb API  in my client only mod.

I've got everything working in the dev environment, but it has this requirement that it needs a properties file in the "root of the classpath."  

It uses this line to pull that file:

UsbHostManager.class.getClassLoader().getResourceAsStream(JAVAX_USB_PROPERTIES_FILE);

where JAVAX_USB_PROPERTIES_FILE is just the name of the file it is looking for without any subdirectory.

The relevant package is shadowed into the jar and the properties file is at the root of the jar.  Everything looks right to me, but it can't find the file.

I also tried running MY_MOD_CLASS.class.getClassLoader().getResourceAsStream(JAVAX_USB_PROPERTIES_FILE); in case the shadowing had messed something up.  It still comes back null.

I've been struggling with this for a while.  My only conclusion is that getResourceAsStream must not search the way I thought it did.  I'd appreciate any direction you can give.

Thanks.

 

 

Link to comment
Share on other sites

I figured this out.  Turns out, it's not really Forge related, but I'll leave the answer here in case it helps someone else out.

The package is javax.usb. 

The file is javax.usb.properties.

I was having some issues so when I shadowed in the package, so I told shadow to relocate it to com.github.theredwagoneer.javax.usb.

What I didn't know is that besides relocating actual package references, shadow actually relocated strings that match the package pattern.  However, it didn't rename resource filenames or resource file contents.  So the mod was looking for  com.github.theredwagoneer.javax.usb.properties, but all that was there was javax.usb.properties.  The string inside the file needed to change too.  Relocated those manually.  All works now.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.