Java无法找到ResteasyClient,尽管所有内容都在pom中占了一席之地

Mad*_*vap 0 java rest maven

在我的原型项目中,我致力于实现非常简单的REST服务 - 服务器(后端)和客户端,实际上也是服务器(前端).后端服务器工作正常,但与客户端我遇到了非常非常奇怪的问题.在Eclipse中,我有一个项目"frontend",它有一个名为FrontEndPageBean.java的bean:

package org.mader.demo.frontend;

import javax.faces.bean.*;
import javax.ws.rs.core.*;

/** Bean to show off frontend handling of REST. */
@ManagedBean
public class FrontEndPageBean
{
  /**
   * Resolve data from backend through REST service.
   * @return Data as text.
   */
  public String getRestData()
  { // Retrieve RESTful service using client API from JAX-RS 2.0

    ResteasyClient client = new ResteasyClientBuilder().build();
    ResteasyWebTarget target = client.target("http://127.0.0.1:8080/backend/rest/data/1");

    Response response = target.request().get();
    // Read output in string format
    String value = response.readEntity(String.class);
    System.out.println(value);
    response.close();

    return value;
  }
}
Run Code Online (Sandbox Code Playgroud)

在home.xhtml中调用它是这样的:

Text resolved by REST from backend: #{frontEndPageBean.restData}
Run Code Online (Sandbox Code Playgroud)

这是我的pom:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>org.mader.demo</groupId>
  <artifactId>frontend</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>Frontend App</name>
  <description>Demonstration Frontend App.</description>

  <properties>
    <webapp.directory>src/main/webapp</webapp.directory>
    <jboss.home>${env.JBOSS_HOME}</jboss.home>

    <!-- plugin versions -->
    <version.war.plugin>2.1.1</version.war.plugin>
    <maven.compiler.target>1.7</maven.compiler.target>
    <maven.compiler.source>1.7</maven.compiler.source>

    <!-- other -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <repositories>
    <repository>
      <id>JBOSS_NEXUS</id>
      <url>http://repository.jboss.org/nexus/content/groups/public</url>
    </repository>
  </repositories>

  <dependencyManagement>
    <dependencies>
      <dependency> <!-- JBoss distributes a complete set of Java EE 7 APIs including a Bill of Materials (BOM). -->
        <groupId>org.jboss.spec</groupId>
        <artifactId>jboss-javaee-7.0</artifactId>
        <version>1.0.0.Final</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>

    <!-- Standard libraries. -->
    <dependency> <!-- CDI API -->
      <groupId>javax.enterprise</groupId>
      <artifactId>cdi-api</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency> <!-- Common Annotations API (JSR-250) -->
      <groupId>org.jboss.spec.javax.annotation</groupId>
      <artifactId>jboss-annotations-api_1.2_spec</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency> <!-- RESTeasy -->
      <groupId>org.jboss.resteasy</groupId>
      <artifactId>jaxrs-api</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency> <!-- JSF -->
      <groupId>org.jboss.spec.javax.faces</groupId>
      <artifactId>jboss-jsf-api_2.2_spec</artifactId>
      <scope>provided</scope>
    </dependency>
  </dependencies>

  <build>
    <finalName>${project.artifactId}</finalName>
    <defaultGoal>package</defaultGoal>

    <plugins>
      <plugin> <!-- To use, run: mvn package wildfly:deploy -->
        <groupId>org.wildfly.plugins</groupId>
        <artifactId>wildfly-maven-plugin</artifactId>
        <version>1.0.0.Beta1</version>
      </plugin>
    </plugins>
  </build>
</project>
Run Code Online (Sandbox Code Playgroud)

问题是Eclipse不识别ResteasyClientBuilder,ResteasyClientResteasyWebTarget.在工具提示中,它显示"ResteasyClient无法解析为某种类型".没有可见的导入选项.它不编译.它只是不起作用(TM).

根据有关使用REST的各种页面,ResteasyClient客户端=新的ResteasyClientBuilder().build(); 是犹太洁食的方式.我能想到的唯一事情就是有一些东西可以添加到POM中,有些缺少依赖性.访问http://maven-repository.com/artifact/org.jboss.spec/jboss-javaee-all-7.0/1.0.0.Final没有多大帮助,也没有检查ResteasyClient的代码 - 它看起来应该是已经涵盖.当然我错过了一些东西......

环境:Java 1.7,Eclipse Kepler,Wildfly 8.0

Mad*_*vap 7

问题解决了.实际上,POM中的条目丢失了.

我需要添加其他类似的条目:

<dependency>
  <groupId>org.jboss.resteasy</groupId>
  <artifactId>resteasy-client</artifactId>
  <version>3.0.6.Final</version>
  <scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)

注意完全指定的版本和范围仍然是"提供".

我失去了很多追逐阴影的时间.缺乏直接指定org.jboss.resteasy:在RestEasy的客户端等http://mvnrepository.com/artifact/org.jboss.spec/jboss-javaee-7.0/1.0.0.Final是把我错了万无一失的方法跟踪.我希望这个答案可以帮助任何有同样问题的人.