You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by Sebastien Arbogast <se...@gmail.com> on 2006/07/16 19:54:06 UTC

[M2] Mojo development: access to resources inside the plugin

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?

-- 
Sébastien Arbogast

http://www.sebastien-arbogast.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [M2] Mojo development: access to resources inside the plugin

Posted by Sebastien Arbogast <se...@gmail.com>.
That's exactly what I'm trying to achieve: the foo directory contains
a tree of directories and files that I'd like to copy over to some
target directory.

2006/7/16, Dennis Lundberg <de...@apache.org>:
> 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 <de...@apache.org> 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: users-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: users-help@maven.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Sébastien Arbogast

http://www.sebastien-arbogast.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [M2] Mojo development: access to resources inside the plugin

Posted by Dennis Lundberg <de...@apache.org>.
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 <da...@gmail.com>:
>> Denis suggests to copy contents of URL to a file first before 
>> accessing it.
>>
>> -D
>>
>>
>> On 7/16/06, Sebastien Arbogast <se...@gmail.com> 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 <da...@gmail.com>:
>> > > Thanks
>> > >
>> > > On 7/16/06, Dennis Lundberg <de...@apache.org> 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 <de...@apache.org> 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: users-unsubscribe@maven.apache.org
>> > > > >> For additional commands, e-mail: users-help@maven.apache.org
>> > > > >>
>> > > > >>
>> > > > >
>> > > >
>> > > > 
>> ---------------------------------------------------------------------
>> > > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> > > > For additional commands, e-mail: users-help@maven.apache.org
>> > > >
>> > > >
>> > >
>> > >
>> >
>> >
>> > --
>> > Sébastien Arbogast
>> >
>> > http://www.sebastien-arbogast.com
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> > For additional commands, e-mail: users-help@maven.apache.org
>> >
>> >
>>
>>
> 
> 


-- 
Dennis Lundberg


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [M2] Mojo development: access to resources inside the plugin

Posted by dan tran <da...@gmail.com>.
It means You cannot object a File object in a jar file, so you stuck i guess
unless I am total wrong

-D


On 7/16/06, Sebastien Arbogast <se...@gmail.com> 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 <da...@gmail.com>:
> > Denis suggests to copy contents of URL to a file first before accessing
> it.
> >
> > -D
> >
> >
> > On 7/16/06, Sebastien Arbogast <se...@gmail.com> 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 <da...@gmail.com>:
> > > > Thanks
> > > >
> > > > On 7/16/06, Dennis Lundberg <de...@apache.org> 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 <de...@apache.org> 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: users-unsubscribe@maven.apache.org
> > > > > >> For additional commands, e-mail: users-help@maven.apache.org
> > > > > >>
> > > > > >>
> > > > > >
> > > > >
> > > > >
> ---------------------------------------------------------------------
> > > > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > > > For additional commands, e-mail: users-help@maven.apache.org
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> > > --
> > > Sébastien Arbogast
> > >
> > > http://www.sebastien-arbogast.com
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: users-help@maven.apache.org
> > >
> > >
> >
> >
>
>
> --
> Sébastien Arbogast
>
> http://www.sebastien-arbogast.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: [M2] Mojo development: access to resources inside the plugin

Posted by Sebastien Arbogast <se...@gmail.com>.
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 <da...@gmail.com>:
> Denis suggests to copy contents of URL to a file first before accessing it.
>
> -D
>
>
> On 7/16/06, Sebastien Arbogast <se...@gmail.com> 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 <da...@gmail.com>:
> > > Thanks
> > >
> > > On 7/16/06, Dennis Lundberg <de...@apache.org> 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 <de...@apache.org> 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: users-unsubscribe@maven.apache.org
> > > > >> For additional commands, e-mail: users-help@maven.apache.org
> > > > >>
> > > > >>
> > > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > > For additional commands, e-mail: users-help@maven.apache.org
> > > >
> > > >
> > >
> > >
> >
> >
> > --
> > Sébastien Arbogast
> >
> > http://www.sebastien-arbogast.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
>


-- 
Sébastien Arbogast

http://www.sebastien-arbogast.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [M2] Mojo development: access to resources inside the plugin

Posted by dan tran <da...@gmail.com>.
Denis suggests to copy contents of URL to a file first before accessing it.

-D


On 7/16/06, Sebastien Arbogast <se...@gmail.com> 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 <da...@gmail.com>:
> > Thanks
> >
> > On 7/16/06, Dennis Lundberg <de...@apache.org> 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 <de...@apache.org> 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: users-unsubscribe@maven.apache.org
> > > >> For additional commands, e-mail: users-help@maven.apache.org
> > > >>
> > > >>
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: users-help@maven.apache.org
> > >
> > >
> >
> >
>
>
> --
> Sébastien Arbogast
>
> http://www.sebastien-arbogast.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: [M2] Mojo development: access to resources inside the plugin

Posted by Sebastien Arbogast <se...@gmail.com>.
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 <ma...@gmail.com>:
> 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 <se...@gmail.com> 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 <da...@gmail.com>:
> > > Thanks
> > >
> > > On 7/16/06, Dennis Lundberg <de...@apache.org> 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 <de...@apache.org> 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: users-unsubscribe@maven.apache.org
> > > > >> For additional commands, e-mail: users-help@maven.apache.org
> > > > >>
> > > > >>
> > > > >
> > > >
> > > > ---------------------------------------------------------------------
> > > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > > For additional commands, e-mail: users-help@maven.apache.org
> > > >
> > > >
> > >
> > >
> >
> >
> > --
> > Sébastien Arbogast
> >
> > http://www.sebastien-arbogast.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Sébastien Arbogast

http://www.sebastien-arbogast.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [M2] Mojo development: access to resources inside the plugin

Posted by Mark Hewett <ma...@gmail.com>.
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 <se...@gmail.com> 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 <da...@gmail.com>:
> > Thanks
> >
> > On 7/16/06, Dennis Lundberg <de...@apache.org> 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 <de...@apache.org> 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: users-unsubscribe@maven.apache.org
> > > >> For additional commands, e-mail: users-help@maven.apache.org
> > > >>
> > > >>
> > > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > > For additional commands, e-mail: users-help@maven.apache.org
> > >
> > >
> >
> >
>
>
> --
> Sébastien Arbogast
>
> http://www.sebastien-arbogast.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [M2] Mojo development: access to resources inside the plugin

Posted by Sebastien Arbogast <se...@gmail.com>.
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 <da...@gmail.com>:
> Thanks
>
> On 7/16/06, Dennis Lundberg <de...@apache.org> 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 <de...@apache.org> 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: users-unsubscribe@maven.apache.org
> > >> For additional commands, e-mail: users-help@maven.apache.org
> > >>
> > >>
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > For additional commands, e-mail: users-help@maven.apache.org
> >
> >
>
>


-- 
Sébastien Arbogast

http://www.sebastien-arbogast.com

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [M2] Mojo development: access to resources inside the plugin

Posted by dan tran <da...@gmail.com>.
Thanks

On 7/16/06, Dennis Lundberg <de...@apache.org> 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 <de...@apache.org> 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: users-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: users-help@maven.apache.org
> >>
> >>
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: [M2] Mojo development: access to resources inside the plugin

Posted by Dennis Lundberg <de...@apache.org>.
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 <de...@apache.org> 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: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org


Re: [M2] Mojo development: access to resources inside the plugin

Posted by dan tran <da...@gmail.com>.
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 <de...@apache.org> 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: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: [M2] Mojo development: access to resources inside the plugin

Posted by Dennis Lundberg <de...@apache.org>.
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: users-unsubscribe@maven.apache.org
For additional commands, e-mail: users-help@maven.apache.org