Какво ми липсва в този ant trycatch блок?

Опитвам се да създам блок trycatch в моя ant скрипт. Получавам тази грешка:

* АКТУАЛИЗАЦИЯ *

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.7:run (test-compile) on project PROJECT: An Ant BuildException has occured: Problem: failed to create task or type trycatch
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

around Ant part ...<trycatch>... @ 6:13 in /Users/NAME/Projects/PROJECT-dev/PROJECT-website/target/antrun/build-main.xml
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
    at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
    at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
    at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
    at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
    at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
    at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: An Ant BuildException has occured: Problem: failed to create task or type trycatch
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

around Ant part ...<trycatch>... @ 6:13 in /Users/NAME/Projects/PROJECT-dev/PROJECT-website/target/antrun/build-main.xml
    at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:355)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
    ... 19 more
Caused by: /Users/NAME/Projects/PROJECT-dev/PROJECT-website/target/antrun/build-main.xml:6: Problem: failed to create task or type trycatch
Cause: The name is undefined.
Action: Check the spelling.
Action: Check that any custom tasks/types have been declared.
Action: Check that any <presetdef>/<macrodef> declarations have taken place.

    at org.apache.tools.ant.UnknownElement.getNotFoundException(UnknownElement.java:487)
    at org.apache.tools.ant.UnknownElement.makeObject(UnknownElement.java:419)
    at org.apache.tools.ant.UnknownElement.maybeConfigure(UnknownElement.java:163)
    at org.apache.tools.ant.Task.perform(Task.java:347)
    at org.apache.tools.ant.Target.execute(Target.java:390)
    at org.apache.tools.ant.Target.performTasks(Target.java:411)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
    at org.apache.maven.plugin.antrun.AntRunMojo.execute(AntRunMojo.java:327)
    ... 21 more
[ERROR] 
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Опитах се да следвам примери за try catch, но никой от тях не работи. http://ant-contrib.sourceforge.net/tasks/tasks/trycatch.html

Получавам тази грешка, същото име не е дефинирано във всички случаи. Не знам дали влагам този блок на правилното място, защото се опитвам да го поставя в конкретни фази на изграждане.

Как мога да накарам този trycatch да работи?

* АКТУАЛИЗАЦИЯ *

Все още получавам същите грешки

<dependencies>
...
    <dependency>
        <groupId>ant-contrib</groupId>
        <artifactId>ant-contrib</artifactId>
        <version>1.0b3</version>
    </dependency>
...
</dependencies>

...

            <execution>
                <id>test-compile</id>
                <phase>test-compile</phase>
                <configuration>
                 <tasks>
                      <!-- declare ant-contrib tasks -->
                      <taskdef resource="net/sf/antcontrib/antlib.xml" />
                      <echo message="***** Hello from test-compile phase! *****" />
                      <trycatch>
                          <try>
                              <replaceregexp match="\s+" replace=" " flags="g" byline="true">
                                  <fileset dir="${basedir}/target/ROOT/WEB-INF/views/" includes="**/*.jsp"></fileset>
                              </replaceregexp>
                              <replaceregexp match="&lt;!--.*build.*--&gt;" replace=" " flags="g" byline="true">
                                  <fileset dir="${basedir}/target/ROOT/WEB-INF/views/" includes="**/*.jsp"></fileset>
                              </replaceregexp>
                          </try>
                      </trycatch>
                  </tasks>
                </configuration>
                <goals>
                    <goal>run</goal>
                </goals>
            </execution>

person Jack Shultz    schedule 01.10.2014    source източник


Отговори (1)


trycatch е част от ant-contrib. Така че ще трябва да декларирате зависимост за вашия плъгин от тази библиотека и да декларирате задачите, включени в нея, преди да изпълните задачите в конфигурацията:

<execution>
    <id>test-compile</id>
    <phase>test-compile</phase>
    <configuration>
         <tasks>
              <!-- declare ant-contrib tasks -->
              <taskdef resource="net/sf/antcontrib/antlib.xml" />
              <echo message="***** Hello from test-compile phase! *****" />
              <trycatch>
                  <try>
                      <replaceregexp match="\s+" replace=" " flags="g" byline="true">
                          <fileset dir="${basedir}/target/ROOT/WEB-INF/views/" includes="**/*.jsp"></fileset>
                      </replaceregexp>
                      <replaceregexp match="&lt;!--.*build.*--&gt;" replace=" " flags="g" byline="true">
                          <fileset dir="${basedir}/target/ROOT/WEB-INF/views/" includes="**/*.jsp"></fileset>
                      </replaceregexp>
                  </try>
              </trycatch>
          </tasks>
      </configuration>
      <goals>
          <goal>run</goal>
      </goals>
</execution>
<dependencies>
      <dependency>
          <groupId>ant-contrib</groupId>
          <artifactId>ant-contrib</artifactId>
          <version>1.0b3</version>
      </dependency>
</dependencies>
person M A    schedule 01.10.2014