You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by João Kreuzberg <iv...@gmail.com> on 2008/12/20 07:09:17 UTC

[LOADING CLASS]

Hello Guys,

I have a maven plugin that needs to load classes from the project, but when
I try I get class not found exception, so
I'm guessing I need to configure something to let maven know that the
application class path should also include the existing java classes.

This plugin will via reflection will extract some metadata via reflection
from these classes to generate a couple of XML files.

How can configure my mojo to include the classes from src/main/java (the
actual compiled ones in target/classes/... )?

-- 
Ivanir João Kreuzberg

Re: [LOADING CLASS]

Posted by João Kreuzberg <iv...@gmail.com>.
I was able to fix it by creating a custom URLClassLoader

/*
         * we should only need the generated classes from the main Output
         * directory
         */
        URL[] urls = new URL[] { this.getOutputDirectory().toURI().toURL()
};

        /*
         * Creates a URLClassLoader using as parent the current class
loader.
         */
        URLClassLoader classLoader = new URLClassLoader(urls, Thread
                .currentThread().getContextClassLoader());

        Thread.currentThread().setContextClassLoader(classLoader);

If you guys have a more elegant way to do it via maven, maybe maven already
has something like this and
I can just enable one property?

Thanks,

Joao

On Sat, Dec 20, 2008 at 11:59 PM, João Kreuzberg <iv...@gmail.com>wrote:

> Hello Martin,
>
> could you give me a hint on how that would look like?
>
> I'm not sure how this would look like on the plugin..
>
> Thanks
>
> Joao
>
>
> On Sat, Dec 20, 2008 at 5:57 PM, Martin Gainty <mg...@hotmail.com>wrote:
>
>>
>> put in location pointed to by java.class.path (before other class paths)
>>
>> http://jira.codehaus.org/secure/attachment/38657/guide-maven-classloading.aptMartin______________________________________________ Disclaimer and
>> confidentiality note Everything in this e-mail and any attachments relates
>> to the official business of Sender. This transmission is of a confidential
>> nature and Sender does not endorse distribution to any party other than
>> intended recipient. Sender does not necessarily endorse content contained
>> within this transmission. > Date: Sun, 21 Dec 2008 06:21:33 +1030> From:
>> baerrach@gmail.com> To: users@maven.apache.org> Subject: Re: [LOADING
>> CLASS]> > On Sun, Dec 21, 2008 at 12:58 AM, João Kreuzberg <
>> ivanirjoao@gmail.com> wrote:> > Thanks for the quick response,> >> > This
>> is what I have on my mojo:> >> > *> > * @goal model-to-files> > *> > *
>> @phase compile> > *> > * @requiresDependencyResolution compile> >> > I tried
>> all compile/runtime but I can't still load classes by their names.> >> > Any
>> hints?> >> > Do I need to look up on some special class loader within maven
>> built-in> > libraries?> > Sorry I dont know.> Suggest looking at plugins
>> that do this.> > e.g.> svn:
>> http://svn.apache.org/repos/asf/maven/plugins/tags/maven-checkstyle-plugin-2.2>
>> or> clover> jxr> pmd> > They might have the bits you need to know.> >
>> ---------------------------------------------------------------------> To
>> unsubscribe, e-mail: users-unsubscribe@maven.apache.org> For additional
>> commands, e-mail: users-help@maven.apache.org>
>> _________________________________________________________________
>> Life on your PC is safer, easier, and more enjoyable with Windows Vista(R).
>> http://clk.atdmt.com/MRT/go/127032870/direct/01/
>
>
>
>
> --
> Ivanir João Kreuzberg
>



-- 
Ivanir João Kreuzberg

Re: [LOADING CLASS]

Posted by João Kreuzberg <iv...@gmail.com>.
Hello Martin,

could you give me a hint on how that would look like?

I'm not sure how this would look like on the plugin..

Thanks

Joao

On Sat, Dec 20, 2008 at 5:57 PM, Martin Gainty <mg...@hotmail.com> wrote:

>
> put in location pointed to by java.class.path (before other class paths)
>
> http://jira.codehaus.org/secure/attachment/38657/guide-maven-classloading.aptMartin______________________________________________ Disclaimer and
> confidentiality note Everything in this e-mail and any attachments relates
> to the official business of Sender. This transmission is of a confidential
> nature and Sender does not endorse distribution to any party other than
> intended recipient. Sender does not necessarily endorse content contained
> within this transmission. > Date: Sun, 21 Dec 2008 06:21:33 +1030> From:
> baerrach@gmail.com> To: users@maven.apache.org> Subject: Re: [LOADING
> CLASS]> > On Sun, Dec 21, 2008 at 12:58 AM, João Kreuzberg <
> ivanirjoao@gmail.com> wrote:> > Thanks for the quick response,> >> > This
> is what I have on my mojo:> >> > *> > * @goal model-to-files> > *> > *
> @phase compile> > *> > * @requiresDependencyResolution compile> >> > I tried
> all compile/runtime but I can't still load classes by their names.> >> > Any
> hints?> >> > Do I need to look up on some special class loader within maven
> built-in> > libraries?> > Sorry I dont know.> Suggest looking at plugins
> that do this.> > e.g.> svn:
> http://svn.apache.org/repos/asf/maven/plugins/tags/maven-checkstyle-plugin-2.2>
> or> clover> jxr> pmd> > They might have the bits you need to know.> >
> ---------------------------------------------------------------------> To
> unsubscribe, e-mail: users-unsubscribe@maven.apache.org> For additional
> commands, e-mail: users-help@maven.apache.org>
> _________________________________________________________________
> Life on your PC is safer, easier, and more enjoyable with Windows Vista(R).
> http://clk.atdmt.com/MRT/go/127032870/direct/01/




-- 
Ivanir João Kreuzberg

RE: [LOADING CLASS]

Posted by Martin Gainty <mg...@hotmail.com>.
put in location pointed to by java.class.path (before other class paths)
http://jira.codehaus.org/secure/attachment/38657/guide-maven-classloading.aptMartin ______________________________________________ Disclaimer and confidentiality note Everything in this e-mail and any attachments relates to the official business of Sender. This transmission is of a confidential nature and Sender does not endorse distribution to any party other than intended recipient. Sender does not necessarily endorse content contained within this transmission. > Date: Sun, 21 Dec 2008 06:21:33 +1030> From: baerrach@gmail.com> To: users@maven.apache.org> Subject: Re: [LOADING CLASS]> > On Sun, Dec 21, 2008 at 12:58 AM, João Kreuzberg <iv...@gmail.com> wrote:> > Thanks for the quick response,> >> > This is what I have on my mojo:> >> > *> > * @goal model-to-files> > *> > * @phase compile> > *> > * @requiresDependencyResolution compile> >> > I tried all compile/runtime but I can't still load classes by their names.> >> > Any hints?> >> > Do I need to look up on some special class loader within maven built-in> > libraries?> > Sorry I dont know.> Suggest looking at plugins that do this.> > e.g.> svn:http://svn.apache.org/repos/asf/maven/plugins/tags/maven-checkstyle-plugin-2.2> or> clover> jxr> pmd> > They might have the bits you need to know.> > ---------------------------------------------------------------------> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org> For additional commands, e-mail: users-help@maven.apache.org> 
_________________________________________________________________
Life on your PC is safer, easier, and more enjoyable with Windows Vista®. 
http://clk.atdmt.com/MRT/go/127032870/direct/01/

Re: [LOADING CLASS]

Posted by Barrie Treloar <ba...@gmail.com>.
On Sun, Dec 21, 2008 at 12:58 AM, João Kreuzberg <iv...@gmail.com> wrote:
> Thanks for the quick response,
>
> This is what I have on my mojo:
>
>  *
>  * @goal model-to-files
>  *
>  * @phase compile
>  *
>  * @requiresDependencyResolution compile
>
> I tried all compile/runtime but I can't still load classes by their names.
>
> Any hints?
>
> Do I need to look up on some special class loader within maven built-in
> libraries?

Sorry I dont know.
Suggest looking at plugins that do this.

e.g.
svn:http://svn.apache.org/repos/asf/maven/plugins/tags/maven-checkstyle-plugin-2.2
or
clover
jxr
pmd

They might have the bits you need to know.

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


Re: [LOADING CLASS]

Posted by João Kreuzberg <iv...@gmail.com>.
Thanks for the quick response,

This is what I have on my mojo:

 *
 * @goal model-to-files
 *
 * @phase compile
 *
 * @requiresDependencyResolution compile

I tried all compile/runtime but I can't still load classes by their names.

Any hints?

Do I need to look up on some special class loader within maven built-in
libraries?

Regards,

Joao

On Sat, Dec 20, 2008 at 7:26 AM, Barrie Treloar <ba...@gmail.com> wrote:

> On Sat, Dec 20, 2008 at 4:39 PM, João Kreuzberg <iv...@gmail.com>
> wrote:
> > Hello Guys,
> >
> > I have a maven plugin that needs to load classes from the project, but
> when
> > I try I get class not found exception, so
> > I'm guessing I need to configure something to let maven know that the
> > application class path should also include the existing java classes.
> >
> > This plugin will via reflection will extract some metadata via reflection
> > from these classes to generate a couple of XML files.
> >
> > How can configure my mojo to include the classes from src/main/java (the
> > actual compiled ones in target/classes/... )?
>
> Have you added @requiresDependencyResolution as per
> http://maven.apache.org/developers/mojo-api-specification.html?
> I think that gives you access to the scope you want (maybe compile?)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@maven.apache.org
> For additional commands, e-mail: users-help@maven.apache.org
>
>


-- 
Ivanir João Kreuzberg

Re: [LOADING CLASS]

Posted by Barrie Treloar <ba...@gmail.com>.
On Sat, Dec 20, 2008 at 4:39 PM, João Kreuzberg <iv...@gmail.com> wrote:
> Hello Guys,
>
> I have a maven plugin that needs to load classes from the project, but when
> I try I get class not found exception, so
> I'm guessing I need to configure something to let maven know that the
> application class path should also include the existing java classes.
>
> This plugin will via reflection will extract some metadata via reflection
> from these classes to generate a couple of XML files.
>
> How can configure my mojo to include the classes from src/main/java (the
> actual compiled ones in target/classes/... )?

Have you added @requiresDependencyResolution as per
http://maven.apache.org/developers/mojo-api-specification.html?
I think that gives you access to the scope you want (maybe compile?)

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