On Wed, 28 Sep 2005, Brian Moseley wrote:

Correct, target/classes is not in the classpath when executing maven on a
project. It will only be on the classpath during test excution.

I recommend you create a plugin containing the
org.osaf.cosmo.jackrabbit.RepositoryLoader, unless this is generated code.

Normally you don't use the project sources to build the project itself,
but split that out to a reusable plugin.

But if you really must, you can add the target/classes to the classpath
using some jelly magic. I've tried something like this but I can't create
the correct URL[] parameter, but this should give you a start:

    <j:new var="file" className="java.io.File">
      <j:arg value="target/classes"/>
    </j:new>
    <j:invoke var="url" method="toURL" on="${file}"/>

    <j:invokeStatic var="cthread" method="currentThread" 
className="java.lang.Thread"/>

    <j:invokeStatic var="urlclassloader"
      className="java.net.URLClassLoader"
      method="newInstance"
    >
    <j:arg type="java.net.URL"/> <!-- null, i hope; doesn't work, need [] -->
    <j:arg type="java.lang.ClassLoader" value="${cthread.contextClassLoader}"/>
    </j:invokeStatic>

    <j:invoke method="addURL" on="${urlclassloader}">
      <j:arg value="${url}"/>
    </j:invoke>

and then use the new classloader 'urlclassloader' to load your class.

Another, better, option is to use define:classLoader
(see
http://jakarta.apache.org/commons/jelly/libs/define/tags.html#define:classLoader
)

but then your class needs to be a Tag.

HTH,

        Kenney


> i'm having a classpath issue. the description is fairly lengthy, so bear
> with me while i illustrate with examples...
>
> i have a preGoal for test:test-resources that attains a test:reposetup goal:
>
>    <preGoal name="test:test-resources">
>      <attainGoal name="test:reposetup"/>
>    </preGoal>
>
> test:reposetup calls a tag that i defined in maven.xml using the jelly
> define taglib:
>
>    <goal name="test:reposetup">
>      ...
>      <jackrabbit:loadoverlord ... />
>      ...
>    </goal>
>
> jackrabbit:overlord uses the jelly new tag to instantiate one of my
> classes and invoke a method on it:
>
>    <define:tag name="loadoverlord">
>      ...
>      <j:new var="loader"
>             className="org.osaf.cosmo.jackrabbit.RepositoryLoader"/>
>      ...
>    </define:tag>
>
> this mess fails with a ClassNotFoundException for
> org.osaf.cosmo.jackrabbit.RepositoryLoader.
>
> RepositoryLoader.class is found in target/classes:
>
>    $ find target -name RepositoryLoader.class
>      target/classes/org/osaf/cosmo/jackrabbit/RepositoryLoader.class
>
> so i guess that target/classes is not in the classpath when
> test:test-resources is executed.
>
> so the money question is: how do i add it to the classpath? or am i
> mis-diagnosing the problem?
>
> thanks!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>

--
Kenney Westerhof
http://www.neonics.com
GPG public key: http://www.gods.nl/~forge/kenneyw.key

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

Reply via email to