This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

extract directory from current jar  RSS feed

 
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..
 
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 ...
 
Author
Ranch Hand
Posts: 964
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 :
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!