I'm writing a web application for among things, managing the building and
deploying of applications, and I'm using Ant (1.7.0) as the engine for those
pieces. The basic flow is:
Project p = new Project();
p.init();
p.setUserProperty("ant.file", "common.xml")
ProjectHelper2 ph = new ProjectHelper2
ph.parse(p, "common.xml");
p.executeTarget("myTarget");
The common.xml file contains <taskdef> definitions for PVCS tasks I wrote to
promote, label, get, etc. Those tasks get executed in targets found in
common.xml. Those classes are in a jar file called myPVCS.jar.
During development, I executed my code from a jar file, with any supporting jar
files in my system class path (java -classpath
myApp.jar;myPVCS.jar;ant.jar;log4j.jar;mail.jar.... myApp.myClass). Everything
works fine.
I then create my war file and place all the required jar files in the
web-inf/lib folder. The application fails with a ClassNotFoundException during
the call to the ProjectHelper2 parse method. It cannot find the class defined
in my <taskdef> definition in common.xml. That class is in myPVCS.jar, which is
in the web-inf/lib folder of my war file. If I update the snippet above with
Class c = Class.forName("mypvcstask"), it finds it, so I know my war file
structure is sound.
>From looking at Ant source code, javadoc, and postings I've found, it looks
>like PropertyHelper2 uses a thread context classloader which uses the system
>classloader (the one that started my weblogic instance to which my web app is
>deployed) as a parent. As a test, I put myPVCS.jar in the weblogic classpath
>and it did find the class. Naturally, I don't want to go that route because it
>breaks the whole "fully contained application in a war file" model I'm
>shooting for.
I see references to LoaderUtils, AntClassLoader, and other things, but I can't
figure out how to use them in my case.
Since the class shown above finds classes in my web-inf/lib folder, I believe
what I want is the ability to do something like:
ProjectHelper2 ph2 = new ProjectHelper2();
ph2.setContextClassLoader(this.getClass().getClassLoader());
ph2.parse(p, "common.xml");
What can I do, or am I just trying to do something that can't be done (in an
efficient manner), and I need to rethink my approach.
Thanks,
Kevin
*************************************************************************
This communication, including attachments, is
for the exclusive use of addressee and may contain proprietary,
confidential and/or privileged information. If you are not the intended
recipient, any use, copying, disclosure, dissemination or distribution is
strictly prohibited. If you are not the intended recipient, please notify
the sender immediately by return e-mail, delete this communication and
destroy all copies.
*************************************************************************