I don't think that you can access the directory, as a whole, in the jar. The files in a jar file are only resources available on the class path. Don't know how to enumerate the contents of a directory inside a jar file, sorry.

Sebastien Arbogast wrote:
And would you do that? I mean, foo is a directory, it contains a whole
file tree. I don't quite get it.

2006/7/16, dan tran <[EMAIL PROTECTED]>:
Denis suggests to copy contents of URL to a file first before accessing it.

-D


On 7/16/06, Sebastien Arbogast <[EMAIL PROTECTED]> wrote:
>
> I tried that, based on Dennis' proposition:
>
> URL url = this.getClass().getClassLoader().getResource( "/foo" );
>        try {
>            File servlet = new File(url.toURI());
>            getLog().info(servlet.getAbsolutePath());
>        } catch (URISyntaxException e) {
>            throw new MojoExecutionException(e.getMessage(),e);
>        }
>
> But then I got an exception on the first line of the try block:
> java.lang.IllegalArgumentException: URI is not hierarchical
>
> I was thinking of using IOUtils to copy the content of foo to another
> directory but it seems to be harder than I thought.
>
> 2006/7/16, dan tran <[EMAIL PROTECTED]>:
> > Thanks
> >
> > On 7/16/06, Dennis Lundberg <[EMAIL PROTECTED]> wrote:
> > >
> > > It depends on what you want to do with the resource.
> > >
> > > I used it with
> > > FileUtils.copyURLToFile( url, new File( outputDirectory, filename )
> );
> > > to copy a resource from within the jar file to the target directory.
> > >
> > > --
> > > Dennis Lundberg
> > >
> > > dan tran wrote:
> > > > Dennis, would you suggestion work? since the resource is in a jar,
> > > > and therefore obtaining a "File" object is not possible.
> > > >
> > > > am I missing something?
> > > >
> > > > -D
> > > >
> > > >
> > > > On 7/16/06, Dennis Lundberg <[EMAIL PROTECTED]> wrote:
> > > >>
> > > >> Sebastien Arbogast wrote:
> > > >> > In the plugin I'm working on, I have a src/main/resources/foo
> > > >> > directory and as a result, when the plugin is packaged, I get a
> foo
> > > >> > directory at the root of the plugin jar, and that's fine.
> > > >> >
> > > >> > But now I want to get a java.io.File reference to this foo
> directory
> > > >> > from inside the code of one of my mojos. How can I do that?
> > > >> >
> > > >>
> > > >> You can get a URL which can then be used to create a file like
> this:
> > > >>
> > > >> URL url = this.getClass().getClassLoader().getResource( "/foo" );
> > > >>
> > > >>
> > > >> --
> > > >> Dennis Lundberg
> > > >>
> > > >>
> ---------------------------------------------------------------------
> > > >> To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > >> For additional commands, e-mail: [EMAIL PROTECTED]
> > > >>
> > > >>
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > > For additional commands, e-mail: [EMAIL PROTECTED]
> > >
> > >
> >
> >
>
>
> --
> Sébastien Arbogast
>
> http://www.sebastien-arbogast.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>






--
Dennis Lundberg


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to