Hi,
You need to add the kodo jar as a dependency for your antrun plugin to make it 
available on the classpath.

If you can find your exact jar version in a public repository then go for it, 
otherwise you'll need to drop your jar in your corporate repository, or, 
failing that declare it as system scope, and declare the systempath to where it 
is located (I would advise having it under scm in this case and using a 
relative path).

Then just add it as a dependency to your plugin with your other plugin 
dependencies.
e.g.
                                <dependency>
                                    <groupId>my.org.kodo</groupId>
                                    <artifactId>kodo-jar</artifactId>
                                    <version>1 </version>
       <!-- if you can't put it in a repository-->
                                    <!--scope>system</scope>
                                    <systemPath>path/to/kodo.jar</systemPath-->
                                </dependency>

I've had success with custom tasks with the following syntax in my ant target:

<typedef name="kodoc" classname="kodo.ant.PCEnhancerTask"/>

This should give you more success.

Adam




| Adam Mitchell | Java Software Architect | Tel: +44 (0)207 633 3570 | Mobile:  
| Skype:  | www.playtech.com

This communication contains information which is privileged and confidential 
and is exclusively intended only for the individual or entity named above 
(recipient(s)). If you are not the intended recipient(s) or the person 
responsible for delivering it to the intended recipient(s), you are hereby 
notified that any review, disclosure, dissemination, distribution or 
reproduction of this communication message in any way or act is prohibited. If 
you receive this communication by mistake please notify the sender immediately 
and then destroy any copies of it. Please note that the sender monitors e-mails 
sent or received. Thank you.
-----Original Message-----
From: Eric B [mailto:[email protected]]
Sent: 17 May 2016 01:38
To: Maven Users List <[email protected]>
Subject: How can I define the classloader for maven-antrun-plugin task?

I recently posted this on StackOverflow, but I've had no traction to the 
question there at all.  I'm hoping that this list will have a bit more feedback 
for me.

I'm having some significant issues converting an ant build to a maven build due 
to an ant task that does not exist as a plugin. The AntTask is part of the 
defunct Kodo persistence library (JDO) that is used to byte enhance the 
entities.

In the build.xml, I have the following target defined:

  </taskdef>
  <kodoc directory="${compile.dir}">
     <classpath refid="compiled.classpath"/>
     <fileset dir="${compile.dir}">
     <include name="**/*.jdo"/>
     </fileset>
  </kodoc>

where ${compile.dir} is defined as the directory where javac compiles its 
files, and compiled.classpath is a list of all libs, etc that are required for 
the plugin.

I have translated that to the following maven-antrun-plugin definition:

        <plugin>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.8</version>
            <dependencies>
            ... list of all the dependencies required for the plugin to run ...
            </dependencies>
            <executions>
                <execution>
                    <id>kodo</id>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <phase>compile</phase>
                    <configuration>
                        <target>
                                <fileset id="jdo-files"
dir="${project.build.outputDirectory}">
                                    <include name="**/*.jdo" />
                                </fileset>

                            <path id="myclasspath">
                                <path refid="maven.compile.classpath" />
                                <path refid="maven.plugin.classpath"/>
                            </path>


                            <taskdef name="kodoc"
classname="kodo.ant.PCEnhancerTask" classpathref="myclasspath" >
                            </taskdef>

                            <kodoc
directory="${project.build.outputDirectory}"
classpath="${project.build.outputDirectory}" >
                                <fileset refid="jdo-files"/>
                            </kodoc>
                        </target>
                    </configuration>
                </execution>
            </executions>
        </plugin>

I would have thought it would work the same. And generally speaking, it seems 
to. It finds all the required dependencies and is able to run.

Except in one spot.

In the AntTask definition, there is the following code:

ClassLoader loader = getClass().getClassLoader(); loader.getResource(rsrc);

where the getClass().getClassLoader() is inspected via a debugger to be:

ClassRealm[plugin>org.apache.maven.plugins:maven-antrun-plugin:1.8,
parent: sun.misc.Launcher$AppClassLoader@18b4aac2]

and rsrc points to a filename that is found in /src/main/resources, or more 
specifically in target/classes.

However, when the loader tries to load rsrc, it fails to find the file, as the 
AntRun classloader has no visibility on that folder.

When I debug the same task in a true Ant call (not maven), I see the 
classloader as being:

AntClassLoader[C:\dev\Projects\jigger\jigger_ejb\dist\compile;C:\dev\Projects\jigger\lib_ext\kodo4\jdo.jar;C:\dev\Projects\jigger\lib_ext\kodo4\jpa.jar;C:\dev\Projects\jigger\lib_ext\kodo4\kodo-api.jar;......
all the libs in the ${compiled.classpath} var]

Which has a true visibility on the compile (ie: target/classes) folder, and 
hence is able to load the required resource.

Modifying the AntTask is not really an option or particularly desired.

Is there anyway I can specify a different classloader to the 
maven-antrun-plugin such that it is able to load/find my resource? I've tried 
all the possible combinations I can think of, but no matter which classpath I 
indicate to the task, the classloader always remains the same - the antrun 
classloader which has no visibility on my target folder.

Baring that, is there any other option I have to make this work??
Thanks,

Eric

Reply via email to