After much googling and attempting to find out how to make this work,
I'm emailing for help :)

The ant optional task "replaceregexp" replaces the contents of a file
by using a regular expression.  Because there are multiple regexp
libraries, ant loads the regexp class selected by a property after
the replaceregexp class is loaded.

See http://ant.apache.org/manual/OptionalTasks/replaceregexp.html
for info on the task or for more info on the regexp mapping, see:
http://ant.apache.org/manual/CoreTypes/regexp.html#implementation

So the simplest build.xml would look like this:
<project name="testrun">
  <property name="ant.regexp.regexpimpl"
value="org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp" />
  <target name="dochange">
    <echo>Classpath ${compileClasspath}</echo>
    <taskdef name="replaceregexp"
classname="org.apache.tools.ant.taskdefs.optional.ReplaceRegExp">
       <classpath path="${compileClasspath}"/>
    </taskdef>
    <replaceregexp file='${basedir}/test.h'
                   match='define VERSION'
                   replace='define TEST' />
  </target>
</project>

with test.h having the contents simply "define VERSION" and running
out-of-the-box binary distribution ant 1.6.5, this works fine.

Doing this in maven, though, has issues: maven's filter doesn't
do regular expressions, so I decided to call the build.xml using
antrun.  Note the commented-out dependencies from when I tried
all of the different regexp implementations!

Running out-of-the-box maven 2.0.4 I get the following error.
The class in question
(org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp)
is actually INSIDE the same .jar file that contains the replaceregexp
(org.apache.tools.ant.taskdefs.optional.ReplaceRegExp) : ant-nodeps.jar

Any suggestions?  From googling, I've seen that the maven 1.1 way to
deal
with this was to make the dependencies use "classloader root" but that's
not valid syntax in maven 2!

Thanks for any help or suggestions!

Dana Lacoste
San Diego, CA

--- error output ---

$ mvn process-resources
[INFO] Scanning for projects...
[INFO]
------------------------------------------------------------------------
----
[INFO] Building Test Project
[INFO]    task-segment: [process-resources]
[INFO]
------------------------------------------------------------------------
----
[INFO] [antrun:run {execution: update-version}]
[INFO] Executing tasks

dochange:
     [echo] Classpath C:\DOCUME~1\LACOSTE\d\target\classes;C:\Documents
and
Settings\lacoste\.m2\repository\ant\ant-nodeps\1.6.5\ant-nodeps-1.6.5.ja
r
Trying to override old definition of datatype replaceregexp
[INFO]
------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO]
------------------------------------------------------------------------
[INFO] Error executing ant tasks

Embedded error: The following error occurred while executing this line:
C:\DOCUME~1\LACOSTE\d\build.xml:11: java.lang.ClassNotFoundException:
org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp
[INFO]
------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO]
------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Apr 05 10:02:39 PDT 2007
[INFO] Final Memory: 2M/4M
[INFO]
------------------------------------------------------------------------


--- pom.xml ---

<project xmlns="http://maven.apache.org/POM/4.0.0";
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd";>
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.example.project</groupId>
  <version>1.00-SNAPSHOT</version>
  <artifactId>project</artifactId>
  <packaging>pom</packaging>
  <name>Test Project</name>
  <dependencies>
    <!--
    <dependency>
      <groupId>oro</groupId>
      <artifactId>oro</artifactId>
      <version>2.0.8</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-jakarta-oro</artifactId>
      <version>1.6.1</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-apache-oro</artifactId>
      <version>1.6.5</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-apache-regexp</artifactId>
      <version>1.6.5</version>
    </dependency>
    <dependency>
      <groupId>jakarta-regexp</groupId>
      <artifactId>jakarta-regexp</artifactId>
      <version>1.4</version>
    </dependency>
    -->
    <dependency>
      <groupId>ant</groupId>
      <artifactId>ant-nodeps</artifactId>
      <version>1.6.5</version>
      <scope>compile</scope>
    </dependency>
  </dependencies> 
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-antrun-plugin</artifactId>
        <executions>
          <execution>
            <id>update-version</id>
            <phase>process-resources</phase>
            <configuration>
              <tasks>
                <property name="compileClasspath"
refid="maven.compile.classpath"/>
                <ant antfile="build.xml" dir="." target="dochange"
inheritRefs="true"/>
                <!-- <taskdef name="replaceregexp"
classname="org.apache.tools.ant.taskdefs.optional.ReplaceRegExp">
                    <classpath refid="maven.compile.classpath" />
                </taskdef>
                <property name="ant.regexp.regexpimpl"
value="org.apache.tools.ant.util.regexp.JakartaRegexpRegexp"/>
                <property name="ant.regexp.regexpimpl"
value="org.apache.tools.ant.util.regexp.JakartaOroRegexp"/>
                <property name="ant.regexp.regexpimpl"
value="org.apache.tools.ant.util.regexp.Jdk14RegexpRegexp"/>
                <replaceregexp file='${basedir}/test.h'
                               match='define VERSION'
                               replace='define TEST' />
                -->
              </tasks>
            </configuration>
            <goals>
              <goal>run</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

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

Reply via email to