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