• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

extract directory from current jar

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ...
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
works great , thanks,

i've simply replaced final dirURL by :
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic