Yeah that's what I had thought of eventually. But the content of the
foo directory was already the unzipped version of a war archive. And I
just discovered that when you add a war as a dependency for a webapp
project, the dependency gets unzipped and repackaged with your
resources and other files. I don't understand why and how I can get
the most out of it but it's exactly what I'm trying to achieve: I have
a war containing a basing presentation server (OpenLaszlo to be more
precise), and I want to unpackage it, add my own resources and files
from the src directory and repackage the thing. I just have to figure
out how to cake my plugin collaborate with war plugin now to get what
I want.

2006/7/17, Mark Hewett <[EMAIL PROTECTED]>:
Maybe you can pack your foo directory structure into a JAR that gets
put into your plugin JAR.  You can then try something like:

InputStream is = this.getClass().getClassLoader().getResourceAsStream(
"/foo.jar" );
JarInputStream jis = new JarInputStream(is);
JarEntry je = null;
while ((je = jis.getNextJarEntry()) != null) {
    // write jar entry to file system
}

Note that this is completely untested (not even compiled!), and you
will have to write code to extract each file from the JAR (or google
it), but hopefully it's something that might work for you.

Mark

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]
>
>

---------------------------------------------------------------------
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]

Reply via email to