【问题标题】:What am I missing in this ant trycatch block?我在这个和尝试 catch 块中缺少什么?
【发布时间】:2014-10-01 15:53:01
【问题描述】:

我正在尝试在我的 ant 脚本中创建 trycatch 块。我收到此错误:

* 更新 *

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>

【问题讨论】:

    标签: ant try-catch ant-contrib


    【解决方案1】:

    trycatchant-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>
    

    【讨论】:

      猜你喜欢
      • 2011-01-24
      • 1970-01-01
      • 1970-01-01
      • 2019-07-01
      • 2021-09-19
      • 1970-01-01
      • 2010-12-25
      • 1970-01-01
      • 2023-03-18
      相关资源
      最近更新 更多