简体   繁体   English

java.lang.NoSuchMethodError Ant / Maven通过命令行失败

[英]java.lang.NoSuchMethodError Ant/Maven failing via command line

Having an issue with doing ant builds via command line due to a maven failure. 由于maven故障而导致通过命令行执行ant构建存在问题。 I can build in eclipse without issue, but when trying to execute via command line, Maven chokes and returns the following error: 我可以在没有问题的情况下构建eclipse,但是当尝试通过命令行执行时,Maven会阻塞并返回以下错误:

java.lang.NoSuchMethodError: org.apache.maven.artifact.ant.DependenciesTask.setPathType(Ljava/lang/String;) java.lang.NoSuchMethodError:org.apache.maven.artifact.ant.DependenciesTask.setPathType(Ljava / lang / String;)

I have the environment variables M2 M2_HOME and JAVA_HOME set. 我有环境变量M2 M2_HOME和JAVA_HOME设置。 Everything seems to be as it should be but I can't seem to figure out where eclipse is filling in the blanks, when it comes to any dependency methods or libraries. 一切似乎都应该如此,但是当涉及到任何依赖方法或库时,我似乎无法弄清楚eclipse在空白处填充的位置。

POM file POM文件

<?xml version="1.0" encoding="UTF-8"?>
<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.company.webapp</groupId>
    <artifactId>V6</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>company Web Site</name>

    <properties>
        <maven.compiler.target>1.6</maven.compiler.target>
        <maven.compiler.source>1.6</maven.compiler.source>
        <spring.version>3.2.4.RELEASE</spring.version>
        <servlet-api.version>3.0.1</servlet-api.version>
        <jaxb-api.version>2.1</jaxb-api.version>
        <spring-hateoas.version>0.7.0.RELEASE</spring-hateoas.version>
        <junit.version>4.11</junit.version>
        <spring-mvctest.version>1.0.0.M2</spring-mvctest.version>
        <httpclient.version>4.3.3</httpclient.version>
        <jstl.version>1.2</jstl.version>
        <jersey-client.version>1.8</jersey-client.version>
        <jackson-mapper-asl.version>1.9.13</jackson-mapper-asl.version>
        <jackson-core.version>2.4.0</jackson-core.version>
        <jackson-databind.version>2.4.3</jackson-databind.version>
        <logback-spring.version>1.0-SNAPSHOT</logback-spring.version>
        <logback-classic.version>1.0.13</logback-classic.version>
        <slf4j.version>1.7.5</slf4j.version>
        <company-ws-util.version>1.1.5-SNAPSHOT</company-ws-util.version>
        <company-util-misc.version>1.2.31-SNAPSHOT</company-util-misc.version>
        <company-util-cache.version>1.4.7-SNAPSHOT</company-util-cache.version>
        <java-mail.version>1.4</java-mail.version>
        <commons-lang3.version>3.1</commons-lang3.version>
    </properties>

    <dependencies>      
        <!-- Spring 3 dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${httpclient.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${commons-lang3.version}</version>
        </dependency>

        <!-- Java Mail API -->
        <dependency>
            <groupId>javax.mail</groupId>
            <artifactId>mail</artifactId>
            <version>${java-mail.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${servlet-api.version}</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
        </dependency>

        <dependency>
              <groupId>com.sun.jersey</groupId>
              <artifactId>jersey-client</artifactId>
              <version>${jersey-client.version}</version>
        </dependency>

        <!-- Jackson JSON Mapper -->
        <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-mapper-asl</artifactId>
            <version>${jackson-mapper-asl.version}</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>${jackson-databind.version}</version>
        </dependency>

        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-core</artifactId>
            <version>${jackson-core.version}</version>
        </dependency>

        <!-- Internal Libraries -->
        <dependency>
            <groupId>com.company.util</groupId>
            <artifactId>company-util-misc</artifactId>
            <version>${company-util-misc.version}</version>
        </dependency>

        <dependency>    
            <groupId>com.company.ws.util</groupId>
            <artifactId>company-ws-util</artifactId>
            <version>${company-ws-util.version}</version>
        </dependency>
        <dependency>    
            <groupId>com.company.util</groupId>
            <artifactId>company-util-cache</artifactId>
            <version>${company-util-cache.version}</version>
        </dependency>

        <!-- Logging -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback-classic.version}</version>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>${slf4j.version}</version>
        </dependency>     

        <!-- Test scope -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
            <version>${junit.version}</version>
        </dependency>
    </dependencies>
    <build>

            <plugins>
              <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>properties-maven-plugin</artifactId>
                <version>1.0-alpha-2</version>
                <executions>
                  <execution>
                    <phase>initialize</phase>
                    <goals>
                      <goal>read-project-properties</goal>
                    </goals>
                    <configuration>
                      <files>
                        <file>${basedir}/build/@mvn@/mvn.build.properties</file>
                      </files>
                    </configuration>
                  </execution>
                </executions>
              </plugin>
              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                  <webResources>
                    <resource>
                      <directory>${basedir}/build/${VERSION}</directory>
                    </resource>
                  </webResources>
                  <webappDirectory>${basedir}/build/${VERSION}</webappDirectory>
                </configuration>
              </plugin>
            </plugins>
        <directory>build/target</directory>
        <finalName>${WARFILE}</finalName>
    </build>
</project>

Full error stack: 完整错误堆栈:

     [echo] MVN BUILD (MAVEN):
     [echo] --------------------------
    [mkdir] Skipping C:\"PATH"\build\@mvn@ because it already exists.
[propertyfile] Updating property file: C:\"PATH"\build\@mvn@\mvn.build.properties
Property "quickbuild" has not been set
     [echo] Executing maven build on Developer machine (other machine)
parsing buildfile jar:file:/C:/Apps/ANT/apache-ant-1.9.5/lib/maven-artifact-ant-2.0.4-dep.jar!/org/apache/maven/artifact/ant/antlib.xml with URI = jar:file:/C:/Apps/ANT/apache-ant-1.9.5/lib/maven-artifact-ant-2.0.4-dep.jar!/org/apache/maven/artifact/ant/antlib.xml from a zip file
  [antcall] Exiting C:\"PATH"\build.xml.

BUILD FAILED
C:\"PATH"\build.xml:349: The following error occurred while executing this line:
C:\"PATH"\build.xml:279: The following error occurred while executing this line:
C:\"PATH"\ant\imports\mvn.xml:46: Maven sub-build has failed! Error in trycatch block:
EXCEPTION BEGIN
C:\"PATH"\ant\imports\mvn.xml:38: java.lang.NoSuchMethodError: org.apache.maven.artifact.ant.DependenciesTask.setPathType(Ljava/lang/String;)V{line.separator}EXCEPTION END
    at org.apache.tools.ant.taskdefs.Exit.execute(Exit.java:164)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at net.sf.antcontrib.logic.TryCatchTask$CatchBlock.execute(TryCatchTask.java:137)
    at net.sf.antcontrib.logic.TryCatchTask.execute(TryCatchTask.java:225)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:217)
    at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:155)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.MacroInstance.execute(MacroInstance.java:396)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.taskdefs.Sequential.execute(Sequential.java:68)
    at net.sf.antcontrib.logic.IfTask.execute(IfTask.java:197)
    at sun.reflect.GeneratedMethodAccessor16.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.TaskAdapter.execute(TaskAdapter.java:155)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
    at org.apache.tools.ant.helper.SingleCheckExecutor.executeTargets(SingleCheckExecutor.java:38)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
    at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:441)
    at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:105)
    at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:293)
    at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
    at org.apache.tools.ant.Task.perform(Task.java:348)
    at org.apache.tools.ant.Target.execute(Target.java:435)
    at org.apache.tools.ant.Target.performTasks(Target.java:456)
    at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1405)
    at org.apache.tools.ant.Project.executeTarget(Project.java:1376)
    at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
    at org.apache.tools.ant.Project.executeTargets(Project.java:1260)
    at org.apache.tools.ant.Main.runBuild(Main.java:853)
    at org.apache.tools.ant.Main.startAnt(Main.java:235)
    at org.apache.tools.ant.launch.Launcher.run(Launcher.java:285)
    at org.apache.tools.ant.launch.Launcher.main(Launcher.java:112)

As mentioned in the comments, there is a difference between the version of the Maven Ant tasks used in Eclipse versus the one used on the command line. 正如评论中所提到的,Eclipse中使用的Maven Ant任务版本与命令行中使用的版本之间存在差异。 Eclipse seems to be using a newer version of this library in which the method DependenciesTask.setPathType(String) exists whereas the command line is relying on an older version. Eclipse似乎使用此库的较新版本,其中存在DependenciesTask.setPathType(String)方法,而命令行依赖于旧版本。

You may be able to get more information on which version of the Ant tasks Eclipse is using by checking the preferences page. 通过检查首选项页面,您可以获得有关Eclipse正在使用的Ant任务版本的更多信息。 Try navigating to Window -> Preferences -> Ant -> Runtime and see Classpath tab for external libraries. 尝试导航到Window - > Preferences - > Ant - > Runtime,然后查看外部库的Classpath选项卡。

On the other hand, from the output of the Ant build: 另一方面,从Ant构建的输出:

[echo] Executing maven build on Developer machine (other machine)
parsing buildfile jar:file:/C:/Apps/ANT/apache-ant-1.9.5/lib/maven-artifact-ant-2.0.4-dep.jar!/org/apache/maven/artifact/ant/antlib.xml with URI = jar:file:/C:/Apps/ANT/apache-ant-1.9.5/lib/maven-artifact-ant-2.0.4-dep.jar!/org/apache/maven/artifact/ant/antlib.xml from a zip file

the command line is obviously using version 2.0.4 which is located in the lib folder of the Ant home directory. 命令行显然使用的是版本2.0.4,它位于Ant主目录的lib文件夹中。 Checking this page , the latest version is 2.1.3 which does contain the missing method. 检查此页面 ,最新版本是2.1.3,其中包含缺少的方法。 So it would make sense to update the version in the Ant lib directory to be the latest one (check the download link on the project page). 因此,将Ant lib目录中的版本更新为最新版本是有意义的(检查项目页面上的下载链接)。

You can always run maven against same settings.xml which you are using for eclipse(Use "-s ") 您始终可以针对用于eclipse的相同settings.xml运行maven(使用“-s”)

We can get more description by running maven in debug move : Use "-X" while running maven. 我们可以通过在调试移动中运行maven来获得更多描述:在运行maven时使用“-X”。

Okay, here's the exact problem and solution in detail... 好的,这是确切的问题和解决方案......

I was confused over a couple things. 我对几件事感到困惑。 Originally, I wasn't clear that maven-ant-tasks and maven-artifact-ant were the same library and I thought that I needed to install maven-ant-tasks, but that was cleared up with original responses. 最初,我不清楚maven-ant-tasks和maven-artifact-ant是同一个库,我认为我需要安装maven-ant-tasks,但是这已经被原始响应清理了。 Secondly, when researching how to update (or install) maven-ant-tasks I found out that this was already happening in my configuration, and since the correct methods appeared as early as 2.1.2, I could see that the following configuration in our system was correct, and that the problem shouldn't be happening 其次,在研究如何更新(或安装)maven-ant-tasks时,我发现这已经在我的配置中发生,并且由于早在2.1.2就出现了正确的方法,我可以看到我们的以下配置系统是正确的,问题不应该发生

My project config code: 我的项目配置代码:

<taskdef resource="org/apache/maven/artifact/ant/antlib.xml" uri="antlib:org.apache.maven.artifact.ant">
  <classpath>
    <pathelement location="${basedir}/ant/lib/maven-ant-tasks-2.1.3.jar"/>
  </classpath>
</taskdef>

The documentation supports this here: http://maven.apache.org/ant-tasks/installation.html (slightly different code but same purpose and result) 文档支持这里: http//maven.apache.org/ant-tasks/installation.html (略有不同的代码,但目的和结果相同)

Alas, the problem was still occurring... After a -verbose dump and compare of both eclipse build output as well as command-line output, I could see that the only difference was that the command line was trying to call both files, and when it did, only a couple of the needed methods were loading. 唉,问题仍在发生......经过-verbose转储并比较eclipse构建输出和命令行输出后,我可以看到唯一的区别是命令行试图调用这两个文件,当它这样做时,只需要加载几个所需的方法。

After looking in the ant directories for eclipse, I noticed that the maven-ant-tasks library was simply not there, so I tried removing it from my own install and Voila!... I would have expected a polymorphic result, but apparently it doesn't work that way. 在查看eclipse的ant目录之后,我注意到maven-ant-tasks库根本就不存在,所以我尝试将它从我自己的安装中移除并且Voila!...我本来期望得到多态的结果,但显然它不这样做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM