ANT Regexp probléma

Üdv!

Van egy ANT targetem ami használja a regexp taskot. Ha ezt a targetet futtatom Eclipse-ből (külön Java process-el) akkor működik minden, ha egy servletből indítom a targetet, akkor elszáll ezzel a hibával:

build_db.xml:826: No supported regular expression matcher found: java.lang.ClassNotFoundException: No ClassLoaders found for: org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp

Elég sokat kerestem a megoldást a problémára. Itt egy részlet az ANT manualjából ami érdekes lehet:

The regexp mapper needs a supporting library and an implementation of org.apache.tools.ant.util.regexp.RegexpMatcher that hides the specifics of the library. Since Ant 1.8.0 Ant requires Java 1.4 to run, so the implementation based on the java.util.regex package will always be available. You can still use Jakarta ORO or Jakarta Regex instead if your provide the corresponding jar in your CLASSPATH.

For information about using gnu.regexp or gnu.rex with Ant, see this article.

If you want to use one of the regular expression libraries other than java.util.regex you need to also use the corresponding ant-[apache-oro, apache-regexp].jar from the Ant release you are using. Make sure, both will be loaded from the same classpath, that is either put them into your CLASSPATH, ANT_HOME/lib directory or a nested element of the mapper - you cannot have ant-[apache-oro, apache-regexp].jar in ANT_HOME/lib and the library in a nested .


Ant will choose the regular-expression library based on the following algorithm:

If the system property ant.regexp.matcherimpl has been set, it is taken as the name of the class implementing org.apache.tools.ant.util.regexp.RegexpMatcher that should be used.
If it has not been set, uses the JDK 1.4 classes.

Mivel nem JDK 1.4-et használok ezért valahogy be kéne állítani az ant.regexp.matcherimpl system propertyt. Mondjuk az érdekes, hogy ha meg Eclipse-ből futtatom, akkor nem száll el ilyen hibával és semilyen property nincs neki beállítva. Elvileg ugyanazokat a libeket kéne használnia, de valahogy mégse mert, akkor működne. A gond viszont az, hogy az ant.jar fájlba az org.apache.tools.ant.util.regexp csomagba nincsen olyan osztály amely implementálja a RegexpMatcher osztályt. Pedig elvileg ott kéne lennie és akkor tudnék ra hivatkozni.

Próbáltam behúzni az ant-apache-oro.jar-t is mert ott is van egy iylen csomag, hogy org.apache.tools.ant.util.regexp és benne van a JakartaOroRegexp ami implementálja a RegexpMatcher osztályt. Aztán beállítottam a system propertyt:

project.setProperty("ant.regexp.regexpimpl", "org.apache.tools.ant.util.regexp.JakartaOroRegexp");

Ekkor meg ezt az osztályt nem találja. A tippem az, hogy azért nem mert nem az ant-apache-oro.jar-ban keresi az osztályt hanem az ant.jar-ban mivel a csomagnév ugyanaz.

Három kérdésem lenne:

Hogy lehet működésre bírni az oro regexp-et
Miért működik a dolog ha Eclipse-ből futtatom a targetet
Meg tudom e nézni valahogy, hogy melyik regexp-et használja az ANT futás közben (ezzel közelebb kerülnék a második kérdéshez)

Hozzászólások

Eclipse alatt egy classloader tolt be mindent, servlet container eseten kicsit nyakatekertebb tud lenni a tortenet. Celszeru az antot es a fuggosegeit a a war lib konyvtaraba berakni.

Úgy tettem. Csináltam a WEB-INF alá egy ant mappát és oda raktam a scriptet, valamint mellé raktam még a lib-eket amire szüksége van és a class-okat (a saját task osztályokat). A lib alá beraktam az ant-apache-oro-t és a jakarta-oro-t. De még mindig nem képes megtalálni az osztályt.

Így néz ki a scriptem eleje:

< property name="projectSrc" value="${basedir}" />
< property name="baseLibrariesDir" value="${basedir}/lib" />

< path id="client.libraries" >
< pathelement path="${basedir}/classes"/ >
< fileset dir="${baseLibrariesDir}" >< include name="*.jar" />
< /path >

Tehát behúzok mindent ami a lib alatt van és jar.

Így néz ki a target ahol elhasal a regexp-nél:


< target name="migrateDatabase" description="migrates existing database" depends="parametrizeMigrationsForward" >
< taskdef resource="net/sf/antcontrib/antlib.xml" >

< if >
< matches pattern=".*sql" string="${temppath}" />
...........
...............
..................