You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by James Carman <jc...@carmanconsulting.com> on 2007/04/03 19:49:23 UTC

Using containing project's classpath within mojo...

All,

I am developing a simple mojo which needs to access classes defined within
the project in which it is used.  But, they don't seem to be visible.  I am
writing a mojo that can execute a "loader" (loads data into our database)
object.  It takes a parameter that tells which loader class to use.  Anyway,
I now want to use that mojo within another project to run a loader defined
within that project.  When I try to instantiate that class, it's not
available.  Is there something special I need to do to tell Maven to include
the current project's classpath in my mojo's environment?

James

Re: Using containing project's classpath within mojo...

Posted by James Carman <jc...@carmanconsulting.com>.
Some of them are "provided", but I'm sure I have some regular ones in
there.  I'm working on another issue right now.  I'll be back on that
shortly.  More to follow...

On 4/4/07, Johan Lindquist <jo...@kawoo.co.uk> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Indeed they should - what do you have the dependencies marked up as?
>
> Johan
>
> James Carman wrote:
> > Johan,
> >
> > The only thing that shows up when I look at what's in that list is the
> > target/classes directory of the containing project.  Is that right?
> > Shouldn't the dependencies show up too?
> >
> > James
> >
> > On 4/4/07, James Carman <jc...@carmanconsulting.com> wrote:
> >>
> >> Johan,
> >>
> >> I think I see what you mean.  I'll give it a whirl when I get to work
> >> today.  Thanks for your help!
> >>
> >> James
> >>
> >> On 4/4/07, Johan Lindquist <jo...@kawoo.co.uk> wrote:
> >> >
> > Hi James & James,
> >
> > The classpath element list is simply a list of strings (to locations
> > within the repository).  Please see attached Mojo for a simple example.
> >
> > One issue with this is that some classes (in your case, most likely the
> > spring classes) will be loaded in the URLClassloader as well as in the
> > Mojo class loader.  So you may have to add a reference to the parent
> > loader in this case (and filter out any duplicate libraries from the
> > above list.  Did that make sense?
> >
> > Cheers,
> >
> > Johan
> >
> >> James CE Johnson wrote:
> >> James, Johan,
> >
> >> Please copy me on this if it goes off-list. I'm trying to write a
> >>> MoJo
> > that
> >> uses a utility that uses Spring and I'm getting what I think is a
> >> classloader issue. If you solve it for your case I suspect I can use
> > the
> >> same solution for my own issue: http://rafb.net/p/fOEW5I52.html
> >
> >> Thanks!
> >> James
> >
> >>> Sorry, forget exactly what it is but if you can wait 12 hours I can
> > look
> >>> it up ;)
> >>>
> >>> Found it in some of the maven APIs if that helps.
> >>>
> >>> And no, not on every list ;)
> >>>
> >>> Johan
> >>>
> >>> I forget what it is - not at work an
> >>>
> >>> James Carman wrote:
> >>>> Johan,
> >>>>
> >>>> What kind of objects should I expect in that list?
> >>>>
> >>>> James
> >>>>
> >>>> p.s. Are you on every mailing list? :-)
> >>>>
> >>>>
> >>>> On 4/3/07, Johan Lindquist < johan@kawoo.co.uk> wrote:
> >>>>> Hi James,
> >>>>>
> >>>>> Try using the following property in you Mojo.
> >>>>>
> >>>>>     /**
> >>>>>      * The classpath elements of the project.
> >>>>>      *
> >>>>>      * @parameter expression="${project.runtimeClasspathElements}"
> > *
> >>>>> @required
> >>>>>      * @readonly
> >>>>>      */
> >>>>>     private List classpathElements;
> >>>>>
> >>>>> I think in this case, you would have to provide your own
> > classloader
> >>>>> for spring - the classloader for the Mojo does (as far as I
> > understand)
> >>>>> not see the project dependencies.
> >>>>>
> >>>>> cheers,
> >>>>>
> >>>>> Johan
> >>>>>
> >>>>>
> >>>>> James Carman wrote:
> >>>>>> Franz,
> >>>>>>
> >>>>>> Thanks for replying.  Let me explain it a bit more.  I was trying
> > to
> >>>>> gloss
> >>>>>> over things a bit.  Basically, I'm using Spring to instantiate
> >>> the
> >
> >>>>> bean:
> >>>>>> public class RunLoaderMojo extends AbstractMojo
> >>>>>> {
> >>>>>>    /**
> >>>>>>     * @parameter property="loaderBean" expression="${loaderBean}"
> > *
> >>>>> @required
> >>>>>>     */
> >>>>>>    private String loaderBean;
> >>>>>>
> >>>>>>    public void execute() throws MojoExecutionException
> >>>>>>    {
> >>>>>>        // Load all META-INF/beans.xml files on classpath!
> >>>>>>        ClassPathXmlApplicationContext ctx = new
> >>>>>> ClassPathXmlApplicationContext("classpath*:META-INF/beans.xml");
> >>>>>>        getLog().info("Running loader '" + loaderBean + "'...");
> > final
> >>>>> Loader loader = ( Loader )ctx.getBean(loaderBean,
> >>>>> Loader.class
> >>>>>> );
> >>>>>>        loader.execute();
> >>>>>>    }
> >>>>>>
> >>>>>>    public String getLoaderBean()
> >>>>>>    {
> >>>>>>        return loaderBean;
> >>>>>>    }
> >>>>>>
> >>>>>>    public void setLoaderBean(String loaderBean)
> >>>>>>    {
> >>>>>>        this.loaderBean = loaderBean;
> >>>>>>    }
> >>>>>> }
> >>>>>>
> >>>>>> That's my mojo class.  Then, I want to use it in a project like
> > this:
> >>>>>>
> >>>>>> <plugin>
> >>>>>>  <groupId> com.myco.myproj</groupId>
> >>>>>>  <artifactId>maven-loader-plugin</artifactId>
> >>>>>> </plugin>
> >>>>>>
> >>>>>> Then, I try executing the plugin like this (from the project
> >>> dir):
> >
> >>>>>>
> >>>>>> mvn loader:run -DloaderBean=exampleLoader
> >>>>>>
> >>>>>> If I try to use a beans.xml file that's defined within my
> >>> project,
> > it
> >>>>> doesn't even see it on the classpath.  If I put it into one of my
> >>>>> project's
> >>>>>> dependencies (another module of mine), then it sees it fine.  It
> > just
> >>>>> doesn't see anything within the enclosing project.  Does that make
> >>>>> sense?
> >>>>>> James
> >>>>>>
> >>>>>> On 4/3/07, franz see <fr...@gmail.com> wrote:
> >>>>>>>
> >>>>>>> Good day to you, James,
> >>>>>>>
> >>>>>>> Not sure how you're instantiating those classes. Anyway, try
> > adding
> >>>>> those
> >>>>>>> classes in your plugin's dependency ( see [1] ). And if you need
> > the
> >>>>> path
> >>>>>>> to
> >>>>>>> those binaries, see Getting dependency artifact path of [2].
> >>>>>>>
> >>>>>>> Cheers,
> >>>>>>> Franz
> >>>>>>>
> >>>>>>> [1]
> >>>>>>>
> >>>>>
> >>>
> http://maven.apache.org/ref/current/maven-model/maven.html#class_plugin
> >
> >>>>>>> [2] http://docs.codehaus.org/display/MAVENUSER/
> >>>>>>>
> >>>>>>>
> >>>>>>> James Carman-3 wrote:
> >>>>>>>> All,
> >>>>>>>>
> >>>>>>>> I am developing a simple mojo which needs to access classes
> >>>>> defined
> >>>>>>> within
> >>>>>>>> the project in which it is used.  But, they don't seem to be
> >>>>>>> visible.  I
> >>>>>>>> am
> >>>>>>>> writing a mojo that can execute a "loader" (loads data into our
> >>>>>>> database)
> >>>>>>>> object.  It takes a parameter that tells which loader class to
> >>>>> use. Anyway,
> >>>>>>>> I now want to use that mojo within another project to run a
> > loader
> >>>>>>> defined
> >>>>>>>> within that project.  When I try to instantiate that class,
> >>> it's
> >>>>> not available.  Is there something special I need to do to tell
> >>>>> Maven to include
> >>>>>>>> the current project's classpath in my mojo's environment?
> >>>>>>>>
> >>>>>>>> James
> >>>>>>>>
> >>>>>>>>
> >>>>>>> --
> >>>>>>> View this message in context:
> >>>>>>>
> >>>>>
> >
> >>>
> http://www.nabble.com/Using-containing-project%27s-classpath-within-mojo...-tf3519722s177.html#a9821549
> >>>
> >>>>>
> >>>>>>> Sent from the Maven - Users mailing list archive at Nabble.com.
> >>>>>>>
> >>>>>>>
> >>>>>>>
> > ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >>>>>>> For additional commands, e-mail: users-help@maven.apache.org
> >>>>>>>
> >>>>>>>
> >>>>> --
> >>>>> you too?
> >>>>>
> >>>>>
> > ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >>>>> For additional commands, e-mail: users-help@maven.apache.org
> >>>>>
> >>>>>
> >>> --
> >>> you too?
> >>>
> >>>
> >>> ---------------------------------------------------------------------
> > 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
> >
> >
> >
> >> >
> >> >
> >>
>
> - --
> you too?
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGE6pg1Tv8wj7aQ34RArm4AJ9FXklAcsttAp4btnviqY/NOPpsBACdE/eb
> LMaKS20PtI5qUgl1vvyAT14=
> =OsrM
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Using containing project's classpath within mojo...

Posted by Johan Lindquist <jo...@kawoo.co.uk>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Indeed they should - what do you have the dependencies marked up as?

Johan

James Carman wrote:
> Johan,
> 
> The only thing that shows up when I look at what's in that list is the
> target/classes directory of the containing project.  Is that right?
> Shouldn't the dependencies show up too?
> 
> James
> 
> On 4/4/07, James Carman <jc...@carmanconsulting.com> wrote:
>>
>> Johan,
>>
>> I think I see what you mean.  I'll give it a whirl when I get to work
>> today.  Thanks for your help!
>>
>> James
>>
>> On 4/4/07, Johan Lindquist <jo...@kawoo.co.uk> wrote:
>> >
> Hi James & James,
> 
> The classpath element list is simply a list of strings (to locations
> within the repository).  Please see attached Mojo for a simple example.
> 
> One issue with this is that some classes (in your case, most likely the
> spring classes) will be loaded in the URLClassloader as well as in the
> Mojo class loader.  So you may have to add a reference to the parent
> loader in this case (and filter out any duplicate libraries from the
> above list.  Did that make sense?
> 
> Cheers,
> 
> Johan
> 
>> James CE Johnson wrote:
>> James, Johan,
> 
>> Please copy me on this if it goes off-list. I'm trying to write a
>>> MoJo
> that
>> uses a utility that uses Spring and I'm getting what I think is a
>> classloader issue. If you solve it for your case I suspect I can use
> the
>> same solution for my own issue: http://rafb.net/p/fOEW5I52.html
> 
>> Thanks!
>> James
> 
>>> Sorry, forget exactly what it is but if you can wait 12 hours I can
> look
>>> it up ;)
>>>
>>> Found it in some of the maven APIs if that helps.
>>>
>>> And no, not on every list ;)
>>>
>>> Johan
>>>
>>> I forget what it is - not at work an
>>>
>>> James Carman wrote:
>>>> Johan,
>>>>
>>>> What kind of objects should I expect in that list?
>>>>
>>>> James
>>>>
>>>> p.s. Are you on every mailing list? :-)
>>>>
>>>>
>>>> On 4/3/07, Johan Lindquist < johan@kawoo.co.uk> wrote:
>>>>> Hi James,
>>>>>
>>>>> Try using the following property in you Mojo.
>>>>>
>>>>>     /**
>>>>>      * The classpath elements of the project.
>>>>>      *
>>>>>      * @parameter expression="${project.runtimeClasspathElements}"
> *
>>>>> @required
>>>>>      * @readonly
>>>>>      */
>>>>>     private List classpathElements;
>>>>>
>>>>> I think in this case, you would have to provide your own
> classloader
>>>>> for spring - the classloader for the Mojo does (as far as I
> understand)
>>>>> not see the project dependencies.
>>>>>
>>>>> cheers,
>>>>>
>>>>> Johan
>>>>>
>>>>>
>>>>> James Carman wrote:
>>>>>> Franz,
>>>>>>
>>>>>> Thanks for replying.  Let me explain it a bit more.  I was trying
> to
>>>>> gloss
>>>>>> over things a bit.  Basically, I'm using Spring to instantiate
>>> the
> 
>>>>> bean:
>>>>>> public class RunLoaderMojo extends AbstractMojo
>>>>>> {
>>>>>>    /**
>>>>>>     * @parameter property="loaderBean" expression="${loaderBean}"
> *
>>>>> @required
>>>>>>     */
>>>>>>    private String loaderBean;
>>>>>>
>>>>>>    public void execute() throws MojoExecutionException
>>>>>>    {
>>>>>>        // Load all META-INF/beans.xml files on classpath!
>>>>>>        ClassPathXmlApplicationContext ctx = new
>>>>>> ClassPathXmlApplicationContext("classpath*:META-INF/beans.xml");
>>>>>>        getLog().info("Running loader '" + loaderBean + "'...");
> final
>>>>> Loader loader = ( Loader )ctx.getBean(loaderBean,
>>>>> Loader.class
>>>>>> );
>>>>>>        loader.execute();
>>>>>>    }
>>>>>>
>>>>>>    public String getLoaderBean()
>>>>>>    {
>>>>>>        return loaderBean;
>>>>>>    }
>>>>>>
>>>>>>    public void setLoaderBean(String loaderBean)
>>>>>>    {
>>>>>>        this.loaderBean = loaderBean;
>>>>>>    }
>>>>>> }
>>>>>>
>>>>>> That's my mojo class.  Then, I want to use it in a project like
> this:
>>>>>>
>>>>>> <plugin>
>>>>>>  <groupId> com.myco.myproj</groupId>
>>>>>>  <artifactId>maven-loader-plugin</artifactId>
>>>>>> </plugin>
>>>>>>
>>>>>> Then, I try executing the plugin like this (from the project
>>> dir):
> 
>>>>>>
>>>>>> mvn loader:run -DloaderBean=exampleLoader
>>>>>>
>>>>>> If I try to use a beans.xml file that's defined within my
>>> project,
> it
>>>>> doesn't even see it on the classpath.  If I put it into one of my
>>>>> project's
>>>>>> dependencies (another module of mine), then it sees it fine.  It
> just
>>>>> doesn't see anything within the enclosing project.  Does that make
>>>>> sense?
>>>>>> James
>>>>>>
>>>>>> On 4/3/07, franz see <fr...@gmail.com> wrote:
>>>>>>>
>>>>>>> Good day to you, James,
>>>>>>>
>>>>>>> Not sure how you're instantiating those classes. Anyway, try
> adding
>>>>> those
>>>>>>> classes in your plugin's dependency ( see [1] ). And if you need
> the
>>>>> path
>>>>>>> to
>>>>>>> those binaries, see Getting dependency artifact path of [2].
>>>>>>>
>>>>>>> Cheers,
>>>>>>> Franz
>>>>>>>
>>>>>>> [1]
>>>>>>>
>>>>>
>>> http://maven.apache.org/ref/current/maven-model/maven.html#class_plugin
> 
>>>>>>> [2] http://docs.codehaus.org/display/MAVENUSER/
>>>>>>>
>>>>>>>
>>>>>>> James Carman-3 wrote:
>>>>>>>> All,
>>>>>>>>
>>>>>>>> I am developing a simple mojo which needs to access classes
>>>>> defined
>>>>>>> within
>>>>>>>> the project in which it is used.  But, they don't seem to be
>>>>>>> visible.  I
>>>>>>>> am
>>>>>>>> writing a mojo that can execute a "loader" (loads data into our
>>>>>>> database)
>>>>>>>> object.  It takes a parameter that tells which loader class to
>>>>> use. Anyway,
>>>>>>>> I now want to use that mojo within another project to run a
> loader
>>>>>>> defined
>>>>>>>> within that project.  When I try to instantiate that class,
>>> it's
>>>>> not available.  Is there something special I need to do to tell
>>>>> Maven to include
>>>>>>>> the current project's classpath in my mojo's environment?
>>>>>>>>
>>>>>>>> James
>>>>>>>>
>>>>>>>>
>>>>>>> --
>>>>>>> View this message in context:
>>>>>>>
>>>>>
> 
>>> http://www.nabble.com/Using-containing-project%27s-classpath-within-mojo...-tf3519722s177.html#a9821549
>>>
>>>>>
>>>>>>> Sent from the Maven - Users mailing list archive at Nabble.com.
>>>>>>>
>>>>>>>
>>>>>>>
> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>>>>>> For additional commands, e-mail: users-help@maven.apache.org
>>>>>>>
>>>>>>>
>>>>> --
>>>>> you too?
>>>>>
>>>>>
> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>>>> For additional commands, e-mail: users-help@maven.apache.org
>>>>>
>>>>>
>>> --
>>> you too?
>>>
>>>
>>> ---------------------------------------------------------------------
> 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
> 
> 
> 
>> >
>> >
>>

- --
you too?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGE6pg1Tv8wj7aQ34RArm4AJ9FXklAcsttAp4btnviqY/NOPpsBACdE/eb
LMaKS20PtI5qUgl1vvyAT14=
=OsrM
-----END PGP SIGNATURE-----

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


Re: Using containing project's classpath within mojo...

Posted by James Carman <jc...@carmanconsulting.com>.
Johan,

The only thing that shows up when I look at what's in that list is the
target/classes directory of the containing project.  Is that right?
Shouldn't the dependencies show up too?

James

On 4/4/07, James Carman <jc...@carmanconsulting.com> wrote:
>
> Johan,
>
> I think I see what you mean.  I'll give it a whirl when I get to work
> today.  Thanks for your help!
>
> James
>
> On 4/4/07, Johan Lindquist <jo...@kawoo.co.uk> wrote:
> >
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > Hi James & James,
> >
> > The classpath element list is simply a list of strings (to locations
> > within the repository).  Please see attached Mojo for a simple example.
> >
> > One issue with this is that some classes (in your case, most likely the
> > spring classes) will be loaded in the URLClassloader as well as in the
> > Mojo class loader.  So you may have to add a reference to the parent
> > loader in this case (and filter out any duplicate libraries from the
> > above list.  Did that make sense?
> >
> > Cheers,
> >
> > Johan
> >
> > > James CE Johnson wrote:
> > > James, Johan,
> > >
> > > Please copy me on this if it goes off-list. I'm trying to write a MoJo
> > that
> > > uses a utility that uses Spring and I'm getting what I think is a
> > > classloader issue. If you solve it for your case I suspect I can use
> > the
> > > same solution for my own issue: http://rafb.net/p/fOEW5I52.html
> > >
> > > Thanks!
> > > James
> > >
> > >> Sorry, forget exactly what it is but if you can wait 12 hours I can
> > look
> > >> it up ;)
> > >>
> > >> Found it in some of the maven APIs if that helps.
> > >>
> > >> And no, not on every list ;)
> > >>
> > >> Johan
> > >>
> > >> I forget what it is - not at work an
> > >>
> > >> James Carman wrote:
> > >>> Johan,
> > >>>
> > >>> What kind of objects should I expect in that list?
> > >>>
> > >>> James
> > >>>
> > >>> p.s. Are you on every mailing list? :-)
> > >>>
> > >>>
> > >>> On 4/3/07, Johan Lindquist < johan@kawoo.co.uk> wrote:
> > >>>> Hi James,
> > >>>>
> > >>>> Try using the following property in you Mojo.
> > >>>>
> > >>>>     /**
> > >>>>      * The classpath elements of the project.
> > >>>>      *
> > >>>>      * @parameter expression="${project.runtimeClasspathElements}"
> > *
> > >>>> @required
> > >>>>      * @readonly
> > >>>>      */
> > >>>>     private List classpathElements;
> > >>>>
> > >>>> I think in this case, you would have to provide your own
> > classloader
> > >>>> for spring - the classloader for the Mojo does (as far as I
> > understand)
> > >>>> not see the project dependencies.
> > >>>>
> > >>>> cheers,
> > >>>>
> > >>>> Johan
> > >>>>
> > >>>>
> > >>>> James Carman wrote:
> > >>>>> Franz,
> > >>>>>
> > >>>>> Thanks for replying.  Let me explain it a bit more.  I was trying
> > to
> > >>>> gloss
> > >>>>> over things a bit.  Basically, I'm using Spring to instantiate the
> >
> > >>>> bean:
> > >>>>> public class RunLoaderMojo extends AbstractMojo
> > >>>>> {
> > >>>>>    /**
> > >>>>>     * @parameter property="loaderBean" expression="${loaderBean}"
> > *
> > >>>> @required
> > >>>>>     */
> > >>>>>    private String loaderBean;
> > >>>>>
> > >>>>>    public void execute() throws MojoExecutionException
> > >>>>>    {
> > >>>>>        // Load all META-INF/beans.xml files on classpath!
> > >>>>>        ClassPathXmlApplicationContext ctx = new
> > >>>>> ClassPathXmlApplicationContext("classpath*:META-INF/beans.xml");
> > >>>>>        getLog().info("Running loader '" + loaderBean + "'...");
> > final
> > >>>> Loader loader = ( Loader )ctx.getBean(loaderBean,
> > >>>> Loader.class
> > >>>>> );
> > >>>>>        loader.execute();
> > >>>>>    }
> > >>>>>
> > >>>>>    public String getLoaderBean()
> > >>>>>    {
> > >>>>>        return loaderBean;
> > >>>>>    }
> > >>>>>
> > >>>>>    public void setLoaderBean(String loaderBean)
> > >>>>>    {
> > >>>>>        this.loaderBean = loaderBean;
> > >>>>>    }
> > >>>>> }
> > >>>>>
> > >>>>> That's my mojo class.  Then, I want to use it in a project like
> > this:
> > >>>>>
> > >>>>> <plugin>
> > >>>>>  <groupId> com.myco.myproj</groupId>
> > >>>>>  <artifactId>maven-loader-plugin</artifactId>
> > >>>>> </plugin>
> > >>>>>
> > >>>>> Then, I try executing the plugin like this (from the project dir):
> >
> > >>>>>
> > >>>>> mvn loader:run -DloaderBean=exampleLoader
> > >>>>>
> > >>>>> If I try to use a beans.xml file that's defined within my project,
> > it
> > >>>> doesn't even see it on the classpath.  If I put it into one of my
> > >>>> project's
> > >>>>> dependencies (another module of mine), then it sees it fine.  It
> > just
> > >>>> doesn't see anything within the enclosing project.  Does that make
> > >>>> sense?
> > >>>>> James
> > >>>>>
> > >>>>> On 4/3/07, franz see <fr...@gmail.com> wrote:
> > >>>>>>
> > >>>>>> Good day to you, James,
> > >>>>>>
> > >>>>>> Not sure how you're instantiating those classes. Anyway, try
> > adding
> > >>>> those
> > >>>>>> classes in your plugin's dependency ( see [1] ). And if you need
> > the
> > >>>> path
> > >>>>>> to
> > >>>>>> those binaries, see Getting dependency artifact path of [2].
> > >>>>>>
> > >>>>>> Cheers,
> > >>>>>> Franz
> > >>>>>>
> > >>>>>> [1]
> > >>>>>>
> > >>>> http://maven.apache.org/ref/current/maven-model/maven.html#class_plugin
> >
> > >>>>>> [2] http://docs.codehaus.org/display/MAVENUSER/
> > >>>>>>
> > >>>>>>
> > >>>>>> James Carman-3 wrote:
> > >>>>>>> All,
> > >>>>>>>
> > >>>>>>> I am developing a simple mojo which needs to access classes
> > >>>> defined
> > >>>>>> within
> > >>>>>>> the project in which it is used.  But, they don't seem to be
> > >>>>>> visible.  I
> > >>>>>>> am
> > >>>>>>> writing a mojo that can execute a "loader" (loads data into our
> > >>>>>> database)
> > >>>>>>> object.  It takes a parameter that tells which loader class to
> > >>>> use. Anyway,
> > >>>>>>> I now want to use that mojo within another project to run a
> > loader
> > >>>>>> defined
> > >>>>>>> within that project.  When I try to instantiate that class, it's
> > >>>> not available.  Is there something special I need to do to tell
> > >>>> Maven to include
> > >>>>>>> the current project's classpath in my mojo's environment?
> > >>>>>>>
> > >>>>>>> James
> > >>>>>>>
> > >>>>>>>
> > >>>>>> --
> > >>>>>> View this message in context:
> > >>>>>>
> > >>>>
> > http://www.nabble.com/Using-containing-project%27s-classpath-within-mojo...-tf3519722s177.html#a9821549
> > >>>>
> > >>>>>> Sent from the Maven - Users mailing list archive at Nabble.com.
> > >>>>>>
> > >>>>>>
> > >>>>>>
> > ---------------------------------------------------------------------
> > >>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > >>>>>> For additional commands, e-mail: users-help@maven.apache.org
> > >>>>>>
> > >>>>>>
> > >>>> --
> > >>>> you too?
> > >>>>
> > >>>>
> > ---------------------------------------------------------------------
> > >>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> > >>>> For additional commands, e-mail: users-help@maven.apache.org
> > >>>>
> > >>>>
> > >> --
> > >> you too?
> > >>
> > >> ---------------------------------------------------------------------
> > 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
> > >
> > >
> >
> > - --
> > you too?
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v1.4.6 (GNU/Linux)
> > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> >
> > iD8DBQFGE04z1Tv8wj7aQ34RAiRkAJ49FAUcqoTmbq75O1QbQ7sBslATZACggZ8J
> > rzFTCXR2donhJ6vXVAEB7/A=
> > =h/ze
> > -----END PGP SIGNATURE-----
> >
> >
>

Re: Using containing project's classpath within mojo...

Posted by James Carman <jc...@carmanconsulting.com>.
Johan,

I think I see what you mean.  I'll give it a whirl when I get to work
today.  Thanks for your help!

James

On 4/4/07, Johan Lindquist <jo...@kawoo.co.uk> wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi James & James,
>
> The classpath element list is simply a list of strings (to locations
> within the repository).  Please see attached Mojo for a simple example.
>
> One issue with this is that some classes (in your case, most likely the
> spring classes) will be loaded in the URLClassloader as well as in the
> Mojo class loader.  So you may have to add a reference to the parent
> loader in this case (and filter out any duplicate libraries from the
> above list.  Did that make sense?
>
> Cheers,
>
> Johan
>
> > James CE Johnson wrote:
> > James, Johan,
> >
> > Please copy me on this if it goes off-list. I'm trying to write a MoJo
> that
> > uses a utility that uses Spring and I'm getting what I think is a
> > classloader issue. If you solve it for your case I suspect I can use the
> > same solution for my own issue: http://rafb.net/p/fOEW5I52.html
> >
> > Thanks!
> > James
> >
> >> Sorry, forget exactly what it is but if you can wait 12 hours I can
> look
> >> it up ;)
> >>
> >> Found it in some of the maven APIs if that helps.
> >>
> >> And no, not on every list ;)
> >>
> >> Johan
> >>
> >> I forget what it is - not at work an
> >>
> >> James Carman wrote:
> >>> Johan,
> >>>
> >>> What kind of objects should I expect in that list?
> >>>
> >>> James
> >>>
> >>> p.s. Are you on every mailing list? :-)
> >>>
> >>>
> >>> On 4/3/07, Johan Lindquist <jo...@kawoo.co.uk> wrote:
> >>>> Hi James,
> >>>>
> >>>> Try using the following property in you Mojo.
> >>>>
> >>>>     /**
> >>>>      * The classpath elements of the project.
> >>>>      *
> >>>>      * @parameter expression="${project.runtimeClasspathElements}" *
> >>>> @required
> >>>>      * @readonly
> >>>>      */
> >>>>     private List classpathElements;
> >>>>
> >>>> I think in this case, you would have to provide your own classloader
> >>>> for spring - the classloader for the Mojo does (as far as I
> understand)
> >>>> not see the project dependencies.
> >>>>
> >>>> cheers,
> >>>>
> >>>> Johan
> >>>>
> >>>>
> >>>> James Carman wrote:
> >>>>> Franz,
> >>>>>
> >>>>> Thanks for replying.  Let me explain it a bit more.  I was trying to
> >>>> gloss
> >>>>> over things a bit.  Basically, I'm using Spring to instantiate the
> >>>> bean:
> >>>>> public class RunLoaderMojo extends AbstractMojo
> >>>>> {
> >>>>>    /**
> >>>>>     * @parameter property="loaderBean" expression="${loaderBean}" *
> >>>> @required
> >>>>>     */
> >>>>>    private String loaderBean;
> >>>>>
> >>>>>    public void execute() throws MojoExecutionException
> >>>>>    {
> >>>>>        // Load all META-INF/beans.xml files on classpath!
> >>>>>        ClassPathXmlApplicationContext ctx = new
> >>>>> ClassPathXmlApplicationContext("classpath*:META-INF/beans.xml");
> >>>>>        getLog().info("Running loader '" + loaderBean + "'...");
> final
> >>>> Loader loader = ( Loader )ctx.getBean(loaderBean,
> >>>> Loader.class
> >>>>> );
> >>>>>        loader.execute();
> >>>>>    }
> >>>>>
> >>>>>    public String getLoaderBean()
> >>>>>    {
> >>>>>        return loaderBean;
> >>>>>    }
> >>>>>
> >>>>>    public void setLoaderBean(String loaderBean)
> >>>>>    {
> >>>>>        this.loaderBean = loaderBean;
> >>>>>    }
> >>>>> }
> >>>>>
> >>>>> That's my mojo class.  Then, I want to use it in a project like
> this:
> >>>>>
> >>>>> <plugin>
> >>>>>  <groupId>com.myco.myproj</groupId>
> >>>>>  <artifactId>maven-loader-plugin</artifactId>
> >>>>> </plugin>
> >>>>>
> >>>>> Then, I try executing the plugin like this (from the project dir):
> >>>>>
> >>>>> mvn loader:run -DloaderBean=exampleLoader
> >>>>>
> >>>>> If I try to use a beans.xml file that's defined within my project,
> it
> >>>> doesn't even see it on the classpath.  If I put it into one of my
> >>>> project's
> >>>>> dependencies (another module of mine), then it sees it fine.  It
> just
> >>>> doesn't see anything within the enclosing project.  Does that make
> >>>> sense?
> >>>>> James
> >>>>>
> >>>>> On 4/3/07, franz see <fr...@gmail.com> wrote:
> >>>>>>
> >>>>>> Good day to you, James,
> >>>>>>
> >>>>>> Not sure how you're instantiating those classes. Anyway, try adding
> >>>> those
> >>>>>> classes in your plugin's dependency ( see [1] ). And if you need
> the
> >>>> path
> >>>>>> to
> >>>>>> those binaries, see Getting dependency artifact path of [2].
> >>>>>>
> >>>>>> Cheers,
> >>>>>> Franz
> >>>>>>
> >>>>>> [1]
> >>>>>>
> >>>>
> http://maven.apache.org/ref/current/maven-model/maven.html#class_plugin
> >>>>>> [2] http://docs.codehaus.org/display/MAVENUSER/
> >>>>>>
> >>>>>>
> >>>>>> James Carman-3 wrote:
> >>>>>>> All,
> >>>>>>>
> >>>>>>> I am developing a simple mojo which needs to access classes
> >>>> defined
> >>>>>> within
> >>>>>>> the project in which it is used.  But, they don't seem to be
> >>>>>> visible.  I
> >>>>>>> am
> >>>>>>> writing a mojo that can execute a "loader" (loads data into our
> >>>>>> database)
> >>>>>>> object.  It takes a parameter that tells which loader class to
> >>>> use. Anyway,
> >>>>>>> I now want to use that mojo within another project to run a loader
> >>>>>> defined
> >>>>>>> within that project.  When I try to instantiate that class, it's
> >>>> not available.  Is there something special I need to do to tell
> >>>> Maven to include
> >>>>>>> the current project's classpath in my mojo's environment?
> >>>>>>>
> >>>>>>> James
> >>>>>>>
> >>>>>>>
> >>>>>> --
> >>>>>> View this message in context:
> >>>>>>
> >>>>
> http://www.nabble.com/Using-containing-project%27s-classpath-within-mojo...-tf3519722s177.html#a9821549
> >>>>
> >>>>>> Sent from the Maven - Users mailing list archive at Nabble.com.
> >>>>>>
> >>>>>>
> >>>>>>
> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >>>>>> For additional commands, e-mail: users-help@maven.apache.org
> >>>>>>
> >>>>>>
> >>>> --
> >>>> you too?
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >>>> For additional commands, e-mail: users-help@maven.apache.org
> >>>>
> >>>>
> >> --
> >> you too?
> >>
> >> ---------------------------------------------------------------------
> 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
> >
> >
>
> - --
> you too?
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFGE04z1Tv8wj7aQ34RAiRkAJ49FAUcqoTmbq75O1QbQ7sBslATZACggZ8J
> rzFTCXR2donhJ6vXVAEB7/A=
> =h/ze
> -----END PGP SIGNATURE-----
>
>

Re: Using containing project's classpath within mojo...

Posted by Johan Lindquist <jo...@kawoo.co.uk>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi James & James,

The classpath element list is simply a list of strings (to locations
within the repository).  Please see attached Mojo for a simple example.

One issue with this is that some classes (in your case, most likely the
spring classes) will be loaded in the URLClassloader as well as in the
Mojo class loader.  So you may have to add a reference to the parent
loader in this case (and filter out any duplicate libraries from the
above list.  Did that make sense?

Cheers,

Johan

> James CE Johnson wrote:
> James, Johan,
> 
> Please copy me on this if it goes off-list. I'm trying to write a MoJo that
> uses a utility that uses Spring and I'm getting what I think is a
> classloader issue. If you solve it for your case I suspect I can use the
> same solution for my own issue: http://rafb.net/p/fOEW5I52.html
> 
> Thanks!
> James
> 
>> Sorry, forget exactly what it is but if you can wait 12 hours I can look
>> it up ;)
>>
>> Found it in some of the maven APIs if that helps.
>>
>> And no, not on every list ;)
>>
>> Johan
>>
>> I forget what it is - not at work an
>>
>> James Carman wrote:
>>> Johan,
>>>
>>> What kind of objects should I expect in that list?
>>>
>>> James
>>>
>>> p.s. Are you on every mailing list? :-)
>>>
>>>
>>> On 4/3/07, Johan Lindquist <jo...@kawoo.co.uk> wrote:
>>>> Hi James,
>>>>
>>>> Try using the following property in you Mojo.
>>>>
>>>>     /**
>>>>      * The classpath elements of the project.
>>>>      *
>>>>      * @parameter expression="${project.runtimeClasspathElements}" *
>>>> @required
>>>>      * @readonly
>>>>      */
>>>>     private List classpathElements;
>>>>
>>>> I think in this case, you would have to provide your own classloader
>>>> for spring - the classloader for the Mojo does (as far as I understand)
>>>> not see the project dependencies.
>>>>
>>>> cheers,
>>>>
>>>> Johan
>>>>
>>>>
>>>> James Carman wrote:
>>>>> Franz,
>>>>>
>>>>> Thanks for replying.  Let me explain it a bit more.  I was trying to
>>>> gloss
>>>>> over things a bit.  Basically, I'm using Spring to instantiate the
>>>> bean:
>>>>> public class RunLoaderMojo extends AbstractMojo
>>>>> {
>>>>>    /**
>>>>>     * @parameter property="loaderBean" expression="${loaderBean}" *
>>>> @required
>>>>>     */
>>>>>    private String loaderBean;
>>>>>
>>>>>    public void execute() throws MojoExecutionException
>>>>>    {
>>>>>        // Load all META-INF/beans.xml files on classpath!
>>>>>        ClassPathXmlApplicationContext ctx = new
>>>>> ClassPathXmlApplicationContext("classpath*:META-INF/beans.xml");
>>>>>        getLog().info("Running loader '" + loaderBean + "'..."); final
>>>> Loader loader = ( Loader )ctx.getBean(loaderBean,
>>>> Loader.class
>>>>> );
>>>>>        loader.execute();
>>>>>    }
>>>>>
>>>>>    public String getLoaderBean()
>>>>>    {
>>>>>        return loaderBean;
>>>>>    }
>>>>>
>>>>>    public void setLoaderBean(String loaderBean)
>>>>>    {
>>>>>        this.loaderBean = loaderBean;
>>>>>    }
>>>>> }
>>>>>
>>>>> That's my mojo class.  Then, I want to use it in a project like this:
>>>>>
>>>>> <plugin>
>>>>>  <groupId>com.myco.myproj</groupId>
>>>>>  <artifactId>maven-loader-plugin</artifactId>
>>>>> </plugin>
>>>>>
>>>>> Then, I try executing the plugin like this (from the project dir):
>>>>>
>>>>> mvn loader:run -DloaderBean=exampleLoader
>>>>>
>>>>> If I try to use a beans.xml file that's defined within my project, it
>>>> doesn't even see it on the classpath.  If I put it into one of my
>>>> project's
>>>>> dependencies (another module of mine), then it sees it fine.  It just
>>>> doesn't see anything within the enclosing project.  Does that make
>>>> sense?
>>>>> James
>>>>>
>>>>> On 4/3/07, franz see <fr...@gmail.com> wrote:
>>>>>>
>>>>>> Good day to you, James,
>>>>>>
>>>>>> Not sure how you're instantiating those classes. Anyway, try adding
>>>> those
>>>>>> classes in your plugin's dependency ( see [1] ). And if you need the
>>>> path
>>>>>> to
>>>>>> those binaries, see Getting dependency artifact path of [2].
>>>>>>
>>>>>> Cheers,
>>>>>> Franz
>>>>>>
>>>>>> [1]
>>>>>>
>>>> http://maven.apache.org/ref/current/maven-model/maven.html#class_plugin
>>>>>> [2] http://docs.codehaus.org/display/MAVENUSER/
>>>>>>
>>>>>>
>>>>>> James Carman-3 wrote:
>>>>>>> All,
>>>>>>>
>>>>>>> I am developing a simple mojo which needs to access classes
>>>> defined
>>>>>> within
>>>>>>> the project in which it is used.  But, they don't seem to be
>>>>>> visible.  I
>>>>>>> am
>>>>>>> writing a mojo that can execute a "loader" (loads data into our
>>>>>> database)
>>>>>>> object.  It takes a parameter that tells which loader class to
>>>> use. Anyway,
>>>>>>> I now want to use that mojo within another project to run a loader
>>>>>> defined
>>>>>>> within that project.  When I try to instantiate that class, it's
>>>> not available.  Is there something special I need to do to tell
>>>> Maven to include
>>>>>>> the current project's classpath in my mojo's environment?
>>>>>>>
>>>>>>> James
>>>>>>>
>>>>>>>
>>>>>> --
>>>>>> View this message in context:
>>>>>>
>>>> http://www.nabble.com/Using-containing-project%27s-classpath-within-mojo...-tf3519722s177.html#a9821549
>>>>
>>>>>> Sent from the Maven - Users mailing list archive at Nabble.com.
>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>>>>> For additional commands, e-mail: users-help@maven.apache.org
>>>>>>
>>>>>>
>>>> --
>>>> you too?
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>>> For additional commands, e-mail: users-help@maven.apache.org
>>>>
>>>>
>> --
>> you too?
>>
>> --------------------------------------------------------------------- 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
> 
> 

- --
you too?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGE04z1Tv8wj7aQ34RAiRkAJ49FAUcqoTmbq75O1QbQ7sBslATZACggZ8J
rzFTCXR2donhJ6vXVAEB7/A=
=h/ze
-----END PGP SIGNATURE-----

Re: Using containing project's classpath within mojo...

Posted by James CE Johnson <jc...@tragus.org>.
James, Johan,

Please copy me on this if it goes off-list. I'm trying to write a MoJo that
uses a utility that uses Spring and I'm getting what I think is a
classloader issue. If you solve it for your case I suspect I can use the
same solution for my own issue: http://rafb.net/p/fOEW5I52.html

Thanks!
James

> Sorry, forget exactly what it is but if you can wait 12 hours I can look
> it up ;)
>
> Found it in some of the maven APIs if that helps.
>
> And no, not on every list ;)
>
> Johan
>
> I forget what it is - not at work an
>
> James Carman wrote:
>> Johan,
>>
>> What kind of objects should I expect in that list?
>>
>> James
>>
>> p.s. Are you on every mailing list? :-)
>>
>>
>> On 4/3/07, Johan Lindquist <jo...@kawoo.co.uk> wrote:
>>>
>>> Hi James,
>>>
>>> Try using the following property in you Mojo.
>>>
>>>     /**
>>>      * The classpath elements of the project.
>>>      *
>>>      * @parameter expression="${project.runtimeClasspathElements}" *
>>> @required
>>>      * @readonly
>>>      */
>>>     private List classpathElements;
>>>
>>> I think in this case, you would have to provide your own classloader
>>> for spring - the classloader for the Mojo does (as far as I understand)
>>> not see the project dependencies.
>>>
>>> cheers,
>>>
>>> Johan
>>>
>>>
>>> James Carman wrote:
>>> > Franz,
>>> >
>>> > Thanks for replying.  Let me explain it a bit more.  I was trying to
>>> gloss
>>> > over things a bit.  Basically, I'm using Spring to instantiate the
>>> bean:
>>> >
>>> > public class RunLoaderMojo extends AbstractMojo
>>> > {
>>> >    /**
>>> >     * @parameter property="loaderBean" expression="${loaderBean}" *
>>> @required
>>> >     */
>>> >    private String loaderBean;
>>> >
>>> >    public void execute() throws MojoExecutionException
>>> >    {
>>> >        // Load all META-INF/beans.xml files on classpath!
>>> >        ClassPathXmlApplicationContext ctx = new
>>> > ClassPathXmlApplicationContext("classpath*:META-INF/beans.xml");
>>> >        getLog().info("Running loader '" + loaderBean + "'..."); final
>>> Loader loader = ( Loader )ctx.getBean(loaderBean,
>>> Loader.class
>>> > );
>>> >        loader.execute();
>>> >    }
>>> >
>>> >    public String getLoaderBean()
>>> >    {
>>> >        return loaderBean;
>>> >    }
>>> >
>>> >    public void setLoaderBean(String loaderBean)
>>> >    {
>>> >        this.loaderBean = loaderBean;
>>> >    }
>>> > }
>>> >
>>> > That's my mojo class.  Then, I want to use it in a project like this:
>>> >
>>> > <plugin>
>>> >  <groupId>com.myco.myproj</groupId>
>>> >  <artifactId>maven-loader-plugin</artifactId>
>>> > </plugin>
>>> >
>>> > Then, I try executing the plugin like this (from the project dir):
>>> >
>>> > mvn loader:run -DloaderBean=exampleLoader
>>> >
>>> > If I try to use a beans.xml file that's defined within my project, it
>>> doesn't even see it on the classpath.  If I put it into one of my
>>> project's
>>> > dependencies (another module of mine), then it sees it fine.  It just
>>> doesn't see anything within the enclosing project.  Does that make
>>> sense?
>>> >
>>> > James
>>> >
>>> > On 4/3/07, franz see <fr...@gmail.com> wrote:
>>> >>
>>> >>
>>> >> Good day to you, James,
>>> >>
>>> >> Not sure how you're instantiating those classes. Anyway, try adding
>>> those
>>> >> classes in your plugin's dependency ( see [1] ). And if you need the
>>> path
>>> >> to
>>> >> those binaries, see Getting dependency artifact path of [2].
>>> >>
>>> >> Cheers,
>>> >> Franz
>>> >>
>>> >> [1]
>>> >>
>>> http://maven.apache.org/ref/current/maven-model/maven.html#class_plugin
>>> >> [2] http://docs.codehaus.org/display/MAVENUSER/
>>> >>
>>> >>
>>> >> James Carman-3 wrote:
>>> >> >
>>> >> > All,
>>> >> >
>>> >> > I am developing a simple mojo which needs to access classes
>>> defined
>>> >> within
>>> >> > the project in which it is used.  But, they don't seem to be
>>> >> visible.  I
>>> >> > am
>>> >> > writing a mojo that can execute a "loader" (loads data into our
>>> >> database)
>>> >> > object.  It takes a parameter that tells which loader class to
>>> use. Anyway,
>>> >> > I now want to use that mojo within another project to run a loader
>>> >> defined
>>> >> > within that project.  When I try to instantiate that class, it's
>>> not available.  Is there something special I need to do to tell
>>> Maven to include
>>> >> > the current project's classpath in my mojo's environment?
>>> >> >
>>> >> > James
>>> >> >
>>> >> >
>>> >>
>>> >> --
>>> >> View this message in context:
>>> >>
>>> http://www.nabble.com/Using-containing-project%27s-classpath-within-mojo...-tf3519722s177.html#a9821549
>>>
>>> >>
>>> >> Sent from the Maven - Users mailing list archive at Nabble.com.
>>> >>
>>> >>
>>> >> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> >> For additional commands, e-mail: users-help@maven.apache.org
>>> >>
>>> >>
>>> >
>>>
>>> --
>>> you too?
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>>> For additional commands, e-mail: users-help@maven.apache.org
>>>
>>>
>>
>
> --
> you too?
>
> --------------------------------------------------------------------- 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: Using containing project's classpath within mojo...

Posted by Johan Lindquist <jo...@kawoo.co.uk>.
Sorry, forget exactly what it is but if you can wait 12 hours I can look
it up ;)

Found it in some of the maven APIs if that helps.

And no, not on every list ;)

Johan

I forget what it is - not at work an

James Carman wrote:
> Johan,
> 
> What kind of objects should I expect in that list?
> 
> James
> 
> p.s. Are you on every mailing list? :-)
> 
> 
> On 4/3/07, Johan Lindquist <jo...@kawoo.co.uk> wrote:
>>
>> Hi James,
>>
>> Try using the following property in you Mojo.
>>
>>     /**
>>      * The classpath elements of the project.
>>      *
>>      * @parameter expression="${project.runtimeClasspathElements}"
>>      * @required
>>      * @readonly
>>      */
>>     private List classpathElements;
>>
>> I think in this case, you would have to provide your own classloader for
>> spring - the classloader for the Mojo does (as far as I understand) not
>> see the project dependencies.
>>
>> cheers,
>>
>> Johan
>>
>>
>> James Carman wrote:
>> > Franz,
>> >
>> > Thanks for replying.  Let me explain it a bit more.  I was trying to
>> gloss
>> > over things a bit.  Basically, I'm using Spring to instantiate the
>> bean:
>> >
>> > public class RunLoaderMojo extends AbstractMojo
>> > {
>> >    /**
>> >     * @parameter property="loaderBean" expression="${loaderBean}"
>> >     * @required
>> >     */
>> >    private String loaderBean;
>> >
>> >    public void execute() throws MojoExecutionException
>> >    {
>> >        // Load all META-INF/beans.xml files on classpath!
>> >        ClassPathXmlApplicationContext ctx = new
>> > ClassPathXmlApplicationContext("classpath*:META-INF/beans.xml");
>> >        getLog().info("Running loader '" + loaderBean + "'...");
>> >        final Loader loader = ( Loader )ctx.getBean(loaderBean,
>> Loader.class
>> > );
>> >        loader.execute();
>> >    }
>> >
>> >    public String getLoaderBean()
>> >    {
>> >        return loaderBean;
>> >    }
>> >
>> >    public void setLoaderBean(String loaderBean)
>> >    {
>> >        this.loaderBean = loaderBean;
>> >    }
>> > }
>> >
>> > That's my mojo class.  Then, I want to use it in a project like this:
>> >
>> > <plugin>
>> >  <groupId>com.myco.myproj</groupId>
>> >  <artifactId>maven-loader-plugin</artifactId>
>> > </plugin>
>> >
>> > Then, I try executing the plugin like this (from the project dir):
>> >
>> > mvn loader:run -DloaderBean=exampleLoader
>> >
>> > If I try to use a beans.xml file that's defined within my project, it
>> > doesn't even see it on the classpath.  If I put it into one of my
>> project's
>> > dependencies (another module of mine), then it sees it fine.  It just
>> > doesn't see anything within the enclosing project.  Does that make
>> sense?
>> >
>> > James
>> >
>> > On 4/3/07, franz see <fr...@gmail.com> wrote:
>> >>
>> >>
>> >> Good day to you, James,
>> >>
>> >> Not sure how you're instantiating those classes. Anyway, try adding
>> those
>> >> classes in your plugin's dependency ( see [1] ). And if you need the
>> path
>> >> to
>> >> those binaries, see Getting dependency artifact path of [2].
>> >>
>> >> Cheers,
>> >> Franz
>> >>
>> >> [1]
>> >>
>> http://maven.apache.org/ref/current/maven-model/maven.html#class_plugin
>> >> [2] http://docs.codehaus.org/display/MAVENUSER/
>> >>
>> >>
>> >> James Carman-3 wrote:
>> >> >
>> >> > All,
>> >> >
>> >> > I am developing a simple mojo which needs to access classes defined
>> >> within
>> >> > the project in which it is used.  But, they don't seem to be
>> >> visible.  I
>> >> > am
>> >> > writing a mojo that can execute a "loader" (loads data into our
>> >> database)
>> >> > object.  It takes a parameter that tells which loader class to use.
>> >> > Anyway,
>> >> > I now want to use that mojo within another project to run a loader
>> >> defined
>> >> > within that project.  When I try to instantiate that class, it's not
>> >> > available.  Is there something special I need to do to tell Maven to
>> >> > include
>> >> > the current project's classpath in my mojo's environment?
>> >> >
>> >> > James
>> >> >
>> >> >
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://www.nabble.com/Using-containing-project%27s-classpath-within-mojo...-tf3519722s177.html#a9821549
>>
>> >>
>> >> Sent from the Maven - Users mailing list archive at Nabble.com.
>> >>
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> >> For additional commands, e-mail: users-help@maven.apache.org
>> >>
>> >>
>> >
>>
>> -- 
>> you too?
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
> 

-- 
you too?

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


Re: Using containing project's classpath within mojo...

Posted by James Carman <jc...@carmanconsulting.com>.
Johan,

What kind of objects should I expect in that list?

James

p.s. Are you on every mailing list? :-)


On 4/3/07, Johan Lindquist <jo...@kawoo.co.uk> wrote:
>
> Hi James,
>
> Try using the following property in you Mojo.
>
>     /**
>      * The classpath elements of the project.
>      *
>      * @parameter expression="${project.runtimeClasspathElements}"
>      * @required
>      * @readonly
>      */
>     private List classpathElements;
>
> I think in this case, you would have to provide your own classloader for
> spring - the classloader for the Mojo does (as far as I understand) not
> see the project dependencies.
>
> cheers,
>
> Johan
>
>
> James Carman wrote:
> > Franz,
> >
> > Thanks for replying.  Let me explain it a bit more.  I was trying to
> gloss
> > over things a bit.  Basically, I'm using Spring to instantiate the bean:
> >
> > public class RunLoaderMojo extends AbstractMojo
> > {
> >    /**
> >     * @parameter property="loaderBean" expression="${loaderBean}"
> >     * @required
> >     */
> >    private String loaderBean;
> >
> >    public void execute() throws MojoExecutionException
> >    {
> >        // Load all META-INF/beans.xml files on classpath!
> >        ClassPathXmlApplicationContext ctx = new
> > ClassPathXmlApplicationContext("classpath*:META-INF/beans.xml");
> >        getLog().info("Running loader '" + loaderBean + "'...");
> >        final Loader loader = ( Loader )ctx.getBean(loaderBean,
> Loader.class
> > );
> >        loader.execute();
> >    }
> >
> >    public String getLoaderBean()
> >    {
> >        return loaderBean;
> >    }
> >
> >    public void setLoaderBean(String loaderBean)
> >    {
> >        this.loaderBean = loaderBean;
> >    }
> > }
> >
> > That's my mojo class.  Then, I want to use it in a project like this:
> >
> > <plugin>
> >  <groupId>com.myco.myproj</groupId>
> >  <artifactId>maven-loader-plugin</artifactId>
> > </plugin>
> >
> > Then, I try executing the plugin like this (from the project dir):
> >
> > mvn loader:run -DloaderBean=exampleLoader
> >
> > If I try to use a beans.xml file that's defined within my project, it
> > doesn't even see it on the classpath.  If I put it into one of my
> project's
> > dependencies (another module of mine), then it sees it fine.  It just
> > doesn't see anything within the enclosing project.  Does that make
> sense?
> >
> > James
> >
> > On 4/3/07, franz see <fr...@gmail.com> wrote:
> >>
> >>
> >> Good day to you, James,
> >>
> >> Not sure how you're instantiating those classes. Anyway, try adding
> those
> >> classes in your plugin's dependency ( see [1] ). And if you need the
> path
> >> to
> >> those binaries, see Getting dependency artifact path of [2].
> >>
> >> Cheers,
> >> Franz
> >>
> >> [1]
> >> http://maven.apache.org/ref/current/maven-model/maven.html#class_plugin
> >> [2] http://docs.codehaus.org/display/MAVENUSER/
> >>
> >>
> >> James Carman-3 wrote:
> >> >
> >> > All,
> >> >
> >> > I am developing a simple mojo which needs to access classes defined
> >> within
> >> > the project in which it is used.  But, they don't seem to be
> >> visible.  I
> >> > am
> >> > writing a mojo that can execute a "loader" (loads data into our
> >> database)
> >> > object.  It takes a parameter that tells which loader class to use.
> >> > Anyway,
> >> > I now want to use that mojo within another project to run a loader
> >> defined
> >> > within that project.  When I try to instantiate that class, it's not
> >> > available.  Is there something special I need to do to tell Maven to
> >> > include
> >> > the current project's classpath in my mojo's environment?
> >> >
> >> > James
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >>
> http://www.nabble.com/Using-containing-project%27s-classpath-within-mojo...-tf3519722s177.html#a9821549
> >>
> >> Sent from the Maven - Users mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> >> For additional commands, e-mail: users-help@maven.apache.org
> >>
> >>
> >
>
> --
> you too?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Using containing project's classpath within mojo...

Posted by Johan Lindquist <jo...@kawoo.co.uk>.
Hi James,

Try using the following property in you Mojo.

    /**
     * The classpath elements of the project.
     *
     * @parameter expression="${project.runtimeClasspathElements}"
     * @required
     * @readonly
     */
    private List classpathElements;

I think in this case, you would have to provide your own classloader for
spring - the classloader for the Mojo does (as far as I understand) not
see the project dependencies.

cheers,

Johan


James Carman wrote:
> Franz,
> 
> Thanks for replying.  Let me explain it a bit more.  I was trying to gloss
> over things a bit.  Basically, I'm using Spring to instantiate the bean:
> 
> public class RunLoaderMojo extends AbstractMojo
> {
>    /**
>     * @parameter property="loaderBean" expression="${loaderBean}"
>     * @required
>     */
>    private String loaderBean;
> 
>    public void execute() throws MojoExecutionException
>    {
>        // Load all META-INF/beans.xml files on classpath!
>        ClassPathXmlApplicationContext ctx = new
> ClassPathXmlApplicationContext("classpath*:META-INF/beans.xml");
>        getLog().info("Running loader '" + loaderBean + "'...");
>        final Loader loader = ( Loader )ctx.getBean(loaderBean, Loader.class
> );
>        loader.execute();
>    }
> 
>    public String getLoaderBean()
>    {
>        return loaderBean;
>    }
> 
>    public void setLoaderBean(String loaderBean)
>    {
>        this.loaderBean = loaderBean;
>    }
> }
> 
> That's my mojo class.  Then, I want to use it in a project like this:
> 
> <plugin>
>  <groupId>com.myco.myproj</groupId>
>  <artifactId>maven-loader-plugin</artifactId>
> </plugin>
> 
> Then, I try executing the plugin like this (from the project dir):
> 
> mvn loader:run -DloaderBean=exampleLoader
> 
> If I try to use a beans.xml file that's defined within my project, it
> doesn't even see it on the classpath.  If I put it into one of my project's
> dependencies (another module of mine), then it sees it fine.  It just
> doesn't see anything within the enclosing project.  Does that make sense?
> 
> James
> 
> On 4/3/07, franz see <fr...@gmail.com> wrote:
>>
>>
>> Good day to you, James,
>>
>> Not sure how you're instantiating those classes. Anyway, try adding those
>> classes in your plugin's dependency ( see [1] ). And if you need the path
>> to
>> those binaries, see Getting dependency artifact path of [2].
>>
>> Cheers,
>> Franz
>>
>> [1]
>> http://maven.apache.org/ref/current/maven-model/maven.html#class_plugin
>> [2] http://docs.codehaus.org/display/MAVENUSER/
>>
>>
>> James Carman-3 wrote:
>> >
>> > All,
>> >
>> > I am developing a simple mojo which needs to access classes defined
>> within
>> > the project in which it is used.  But, they don't seem to be
>> visible.  I
>> > am
>> > writing a mojo that can execute a "loader" (loads data into our
>> database)
>> > object.  It takes a parameter that tells which loader class to use.
>> > Anyway,
>> > I now want to use that mojo within another project to run a loader
>> defined
>> > within that project.  When I try to instantiate that class, it's not
>> > available.  Is there something special I need to do to tell Maven to
>> > include
>> > the current project's classpath in my mojo's environment?
>> >
>> > James
>> >
>> >
>>
>> -- 
>> View this message in context:
>> http://www.nabble.com/Using-containing-project%27s-classpath-within-mojo...-tf3519722s177.html#a9821549
>>
>> Sent from the Maven - Users mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
>> For additional commands, e-mail: users-help@maven.apache.org
>>
>>
> 

-- 
you too?

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


Re: Using containing project's classpath within mojo...

Posted by James Carman <jc...@carmanconsulting.com>.
Franz,

Thanks for replying.  Let me explain it a bit more.  I was trying to gloss
over things a bit.  Basically, I'm using Spring to instantiate the bean:

public class RunLoaderMojo extends AbstractMojo
{
    /**
     * @parameter property="loaderBean" expression="${loaderBean}"
     * @required
     */
    private String loaderBean;

    public void execute() throws MojoExecutionException
    {
        // Load all META-INF/beans.xml files on classpath!
        ClassPathXmlApplicationContext ctx = new
ClassPathXmlApplicationContext("classpath*:META-INF/beans.xml");
        getLog().info("Running loader '" + loaderBean + "'...");
        final Loader loader = ( Loader )ctx.getBean(loaderBean, Loader.class
);
        loader.execute();
    }

    public String getLoaderBean()
    {
        return loaderBean;
    }

    public void setLoaderBean(String loaderBean)
    {
        this.loaderBean = loaderBean;
    }
}

That's my mojo class.  Then, I want to use it in a project like this:

<plugin>
  <groupId>com.myco.myproj</groupId>
  <artifactId>maven-loader-plugin</artifactId>
</plugin>

Then, I try executing the plugin like this (from the project dir):

mvn loader:run -DloaderBean=exampleLoader

If I try to use a beans.xml file that's defined within my project, it
doesn't even see it on the classpath.  If I put it into one of my project's
dependencies (another module of mine), then it sees it fine.  It just
doesn't see anything within the enclosing project.  Does that make sense?

James

On 4/3/07, franz see <fr...@gmail.com> wrote:
>
>
> Good day to you, James,
>
> Not sure how you're instantiating those classes. Anyway, try adding those
> classes in your plugin's dependency ( see [1] ). And if you need the path
> to
> those binaries, see Getting dependency artifact path of [2].
>
> Cheers,
> Franz
>
> [1]
> http://maven.apache.org/ref/current/maven-model/maven.html#class_plugin
> [2] http://docs.codehaus.org/display/MAVENUSER/
>
>
> James Carman-3 wrote:
> >
> > All,
> >
> > I am developing a simple mojo which needs to access classes defined
> within
> > the project in which it is used.  But, they don't seem to be visible.  I
> > am
> > writing a mojo that can execute a "loader" (loads data into our
> database)
> > object.  It takes a parameter that tells which loader class to use.
> > Anyway,
> > I now want to use that mojo within another project to run a loader
> defined
> > within that project.  When I try to instantiate that class, it's not
> > available.  Is there something special I need to do to tell Maven to
> > include
> > the current project's classpath in my mojo's environment?
> >
> > James
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Using-containing-project%27s-classpath-within-mojo...-tf3519722s177.html#a9821549
> Sent from the Maven - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>

Re: Using containing project's classpath within mojo...

Posted by franz see <fr...@gmail.com>.
Good day to you, James,

Not sure how you're instantiating those classes. Anyway, try adding those
classes in your plugin's dependency ( see [1] ). And if you need the path to
those binaries, see Getting dependency artifact path of [2].

Cheers,
Franz

[1] http://maven.apache.org/ref/current/maven-model/maven.html#class_plugin
[2] http://docs.codehaus.org/display/MAVENUSER/


James Carman-3 wrote:
> 
> All,
> 
> I am developing a simple mojo which needs to access classes defined within
> the project in which it is used.  But, they don't seem to be visible.  I
> am
> writing a mojo that can execute a "loader" (loads data into our database)
> object.  It takes a parameter that tells which loader class to use. 
> Anyway,
> I now want to use that mojo within another project to run a loader defined
> within that project.  When I try to instantiate that class, it's not
> available.  Is there something special I need to do to tell Maven to
> include
> the current project's classpath in my mojo's environment?
> 
> James
> 
> 

-- 
View this message in context: http://www.nabble.com/Using-containing-project%27s-classpath-within-mojo...-tf3519722s177.html#a9821549
Sent from the Maven - Users mailing list archive at Nabble.com.


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