尝试在Glassfish上创建WebClient时出现NoSuchMethodError

时间:2015-02-09 14:41:05

标签: maven jersey apache-httpclient-4.x htmlunit jersey-2.0

我尝试创建HtmlUnit WebClient以解析Servlet filter服务器上Java EE Glassfish内的Ember应用网页。

servlet代码:

  final WebClient webClient = new WebClient(); // causes error
  HtmlPage page = webClient.getPage(originalUrl);

的pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.enunciate</groupId>
            <artifactId>maven-enunciate-plugin</artifactId>
            <version>1.29</version>
            <executions>
                <execution>
                    <goals>
                        <goal>assemble</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <configFile>enunciate.xml</configFile>
                <enunciateArtifactId/>
                <enunciateArtifactId/>
                <moduleName/>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.2</version>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.6</version>
            <configuration>
                <warSourceExcludes>**/web.xml</warSourceExcludes>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet</artifactId>
        <version>2.15</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>net.sourceforge.htmlunit</groupId>
        <artifactId>htmlunit</artifactId>
        <version>2.15</version>
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.34</version>
    </dependency>

    <dependency>
        <groupId>org.codehaus.enunciate</groupId>
        <artifactId>enunciate-rt</artifactId>
        <version>1.29</version>
    </dependency>

    <dependency>
        <groupId>org.igniterealtime.smack</groupId>
        <artifactId>smack-core</artifactId>
        <version>4.0.6</version>
    </dependency>

    <dependency>
        <groupId>org.igniterealtime.smack</groupId>
        <artifactId>smack-tcp</artifactId>
        <version>4.0.6</version>
    </dependency>

    <dependency>
        <groupId>org.igniterealtime.smack</groupId>
        <artifactId>smack-extensions</artifactId>
        <version>4.0.6</version>
    </dependency>

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.1.0</version>
        <scope>provided</scope>
    </dependency>

    <dependency>
        <groupId>com.googlecode.json-simple</groupId>
        <artifactId>json-simple</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>com.paymill</groupId>
        <artifactId>paymill-java</artifactId>
        <version>5.0.0</version>
    </dependency>

    <dependency>
        <groupId>org.mindrot</groupId>
        <artifactId>jbcrypt</artifactId>
        <version>0.3m</version>
    </dependency>

    <dependency>
        <groupId>com.restfb</groupId>
        <artifactId>restfb</artifactId>
        <version>1.7.1</version>
    </dependency>

    <dependency>
        <groupId>com.google.api-client</groupId>
        <artifactId>google-api-client</artifactId>
        <version>1.19.1</version>
    </dependency>

    <dependency>
        <groupId>com.google.http-client</groupId>
        <artifactId>google-http-client-jackson</artifactId>
        <version>1.19.0</version>
    </dependency>

    <dependency>
        <groupId>com.google.apis</groupId>
        <artifactId>google-api-services-plus</artifactId>
        <version>v1-rev209-1.19.1</version>
    </dependency>

    <dependency>
        <groupId>org.codemonkey.simplejavamail</groupId>
        <artifactId>simple-java-mail</artifactId>
        <version>2.1</version>
    </dependency>

    <dependency>
        <groupId>org.quartz-scheduler</groupId>
        <artifactId>quartz</artifactId>
        <version>2.2.1</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.10</version>
    </dependency>
</dependencies>

错误:

java.lang.NoSuchMethodError: org.apache.http.impl.cookie.BrowserCompatSpecFactory.create(Lorg/apache/http/protocol/HttpContext;)Lorg/apache/http/cookie/CookieSpec;
    at com.gargoylesoftware.htmlunit.CookieManager.<init>(CookieManager.java:54)
    at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:136)
    at com.gargoylesoftware.htmlunit.WebClient.<init>(WebClient.java:199)

2 个答案:

答案 0 :(得分:0)

显然将HtmlUnit依赖项移动到依赖项列表的底部修复了该问题。就像提到的peeskillet一样,这不是一个完整的解决方案,因为我们仍然不知道是什么原因引起了这个问题,但它可以作为第一个解决方案。如果你找到了罪魁祸首,请回答。

答案 1 :(得分:0)

我有同样的错误,但html单位不是解决方案。我将httpclient.jar放到顶部,以解决问题。