• Post Reply Bookmark Topic Watch Topic
  • New Topic

extract directory from current jar

 
Ludovik Lax
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm lookig for the simplest way to extract a directory from the deployed jar at execution.
A resources folder called loader exists under src/main/resources (defined in pom);
How to copy the tree under loader directory at launching jar location ?

I' ve done these code for a simple file :





Instead of parsing all tree as an input stream , have you any oher idea to do this ? A JarResources type or FileUtils doesn't seem to do the stuff..
 
Travis Hein
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
from a class that you know is in the jar file you care about,
 
Ludovik Lax
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that FileUtils doesn't know the file defined :


programs exits anormally on the copyDirectory , but then loader directory has the right path ?


I
 
Travis Hein
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah yes,
because File can't take in a URL kind of expression.

I usually manually transform these url looking things into a path myself. that is, the url will contain the jar file name in it's path (if the code is inside a .jar file).
So we need to remove that.

For example, building on the previous example, after getting the location, I reconstruct the jar:/....!/ url I think in this case I was later opening up the jar file to read its manifest information as well, so you might be able to simplify this if needed.


 
Ludovik Lax
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

problem results in an i/o during opening jar file




Ouput =>

java.util.zip.ZipException: error in opening zip file
at java.util.zip.ZipFile.open(Native Method)


Why jar cannot be open as a zip file ?

returns URI is not hierarchical ...
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arthur Burma wrote:I'm lookig for the simplest way to extract a directory from the deployed jar at execution.
A resources folder called loader exists under src/main/resources (defined in pom);
How to copy the tree under loader directory at launching jar location ?


If you look around you'll find a lot of code that is supposed to work, but it didn't work for me.
Here's what I came up with instead. Your mileage may vary.

 
Ludovik Lax
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
works great , thanks,

i've simply replaced final dirURL by :
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!