• Advertisement
Sign in to follow this  

Moving Files Within Jar

This topic is 638 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been working on a little program recently (details aren't exactly very important at the moment), and I essentially copy a DLL file to a certain location.

 

I finished up the program, and it worked pretty much perfectly. Recently, I wanted to make it more compact so it could be a standalone jar without requiring a folder with assets (i.e the image background, icon, DLL, etc.).

 

I figured out that I could get the image as a resource from the actual jar file/class - that eliminates the need for the image assets in a separate folder.

 

Next, I wanted to store the DLL within the jar file so I could copy it to another location. I've tried everything, honestly. I just can't figure out how I would go about copying the DLL file from within the actual jar file to an external location.

 

Any help is welcome. I'll try everything.

 

Thanks to whomever answers!

Share this post


Link to post
Share on other sites
Advertisement

Do you have to do this via code? Aren't JAR files effectively zip archives or some kind? The only thing I had to hand to test was Minecraft (exe) and I can quite happily open it up as if it is a zip archive. You could potentially do this via code and extract the desired dll to a given location. 

 

I don't know how similar this is but when I build my Android APK it creates 2 different APKs, one for ARM and one for x86. I need to copy the x86 parts and merge them into a single APK to publish. I use a bat script (I guess it's called a script but I'm not sure of the terminology) to do this. It extracts all the files I need then re-archives them all into a single APK. I'm sure you could do something similar but obviously using an external tool (7z in my case) might not be the best option if you are doing this on a user's machine as they may not have it installed.

 

You could possibly do this during installation if you have such a step.

Edited by Nanoha

Share this post


Link to post
Share on other sites

Next, I wanted to store the DLL within the jar file so I could copy it to another location. I've tried everything, honestly. I just can't figure out how I would go about copying the DLL file from within the actual jar file to an external location.


I don't really see the problem. It's been a long while since I did something with Java but if I remember correctly you could trivially get an URL to any file in the .jar you loaded yourself from as an URL and use that URL to open a binary stream. Then just open a binary stream in the location where you want the DLL for writing and copy the content over. A far more interesting problem is going to be picking a sensible location to put the DLL and getting Java and/or the OS to load it there.

Share this post


Link to post
Share on other sites

Well then... I figured it out.

 

Apparently while I was using FileOutputStream, I gave it an empty directory. I was supposed to add the result of the copy I wanted at the end.

 

In the beginning, it was something like:

 

C:\bla\bla\FolderWhereIWantTheDLL

 

now it's:

 

C:\bla\bla\FolderWhereIWantTheDLL\dllName.dll

Share this post


Link to post
Share on other sites

Do you have to do this via code? Aren't JAR files effectively zip archives or some kind? The only thing I had to hand to test was Minecraft (exe) and I can quite happily open it up as if it is a zip archive. You could potentially do this via code and extract the desired dll to a given location. 

 

I don't know how similar this is but when I build my Android APK it creates 2 different APKs, one for ARM and one for x86. I need to copy the x86 parts and merge them into a single APK to publish. I use a bat script (I guess it's called a script but I'm not sure of the terminology) to do this. It extracts all the files I need then re-archives them all into a single APK. I'm sure you could do something similar but obviously using an external tool (7z in my case) might not be the best option if you are doing this on a user's machine as they may not have it installed.

 

You could possibly do this during installation if you have such a step.

 

I didn't want to use any external scripts and whatnot to accomplish what I needed. I eventually ended up fixing it, so yeah!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement