0

我正在使用 intelliJ IDE 并尝试了https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/vision/label

我的 pom.xml 没有显示错误,如下所示:

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

  <modelVersion>4.0.0</modelVersion>
  <packaging>war</packaging>
  <version>1.0-SNAPSHpOT</version>
  <groupId>com.example.endpoints</groupId>
  <artifactId>endpoints</artifactId>

  <parent>
    <artifactId>doc-samples</artifactId>
    <groupId>com.google.cloud</groupId>
    <version>1.0.0</version>
    <relativePath>../..</relativePath>
  </parent>

  <properties>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>

    <maven.war.plugin>2.6</maven.war.plugin>

    <appengine.maven.plugin>1.0.0</appengine.maven.plugin>
    <jetty.maven.plugin>9.3.8.v20160314</jetty.maven.plugin>

    <failOnMissingWebXml>false</failOnMissingWebXml> <!-- REQUIRED -->
  </properties>

  <dependencies>
    <dependency>
      <groupId>com.google.apis</groupId>
      <artifactId>google-api-services-vision</artifactId>
      <version>v1-rev347-1.22.0</version>
    </dependency>
      <dependency>
          <groupId>com.google.api-client</groupId>
          <artifactId>google-api-client</artifactId>
          <version>1.22.0</version>
          <exclusions>
              <exclusion> <!-- exclude an old version of Guava -->
                  <groupId>com.google.guava</groupId>
                  <artifactId>guava-jdk5</artifactId>
              </exclusion>
          </exclusions>
      </dependency>
      <dependency>
          <groupId>com.google.guava</groupId>
          <artifactId>guava</artifactId>
          <version>20.0</version>
      </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <type>jar</type>
      <scope>provided</scope>
    </dependency>
    <!--  Gson: Java to Json conversion -->
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.6.2</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>

  <build>
    <!-- for hot reload of the web application -->
    <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
    <plugins>
      <plugin>  <!-- TEMPORARY -->
        <groupId>com.google.appengine</groupId>
        <artifactId>gcloud-maven-plugin</artifactId>
        <version>2.0.9.121.v20160815</version>
      </plugin>
      <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>appengine-maven-plugin</artifactId>
        <version>${appengine.maven.plugin}</version>
        <configuration>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>${maven.war.plugin}</version>
        <configuration>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>${jetty.maven.plugin}</version>
      </plugin>
    </plugins>
  </build>
</project>

但是,java 类无法解决依赖关系

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.vision.v1.Vision;
import com.google.api.services.vision.v1.VisionScopes;
import com.google.api.services.vision.v1.model.AnnotateImageRequest;
import com.google.api.services.vision.v1.model.AnnotateImageResponse;
import com.google.api.services.vision.v1.model.BatchAnnotateImagesRequest;
import com.google.api.services.vision.v1.model.BatchAnnotateImagesResponse;
import com.google.api.services.vision.v1.model.EntityAnnotation;
import com.google.api.services.vision.v1.model.Feature;
import com.google.api.services.vision.v1.model.Image;
import com.google.common.collect.ImmutableList;

我试过 mvn -U clean install

但没有运气

4

1 回答 1

1

由于您使用的是 Flex 环境。我建议以下

(1) 遵循 Java 中 Flex 的快速入门以确保正确设置:https ://cloud.google.com/appengine/docs/flexible/java/quickstart

  • 首先在本地测试(使用码头,如快速入门所示)
  • 如果您愿意,可以在之后部署到 App Engine Flex

(2) 然后,一旦您知道一切正常(至少在本地使用码头服务器),您可以将以下内容添加到您的 pom.xml

<dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-vision</artifactId>
    <version>0.9.4-beta</version>
</dependency>

这来自此页面:https ://cloud.google.com/vision/docs/reference/libraries#client-libraries-install-java

您还可以在其中找到代码示例。

(3) 顺便说一句:对于身份验证,我建议在您的机器上本地设置一个服务帐户。为此,您需要在 Cloud Console 中创建一个服务帐号,然后在本地下载一个 .json 文件,然后设置环境变量 GOOGLE_APPLICATION_CREDENTIALS 以指向该 .json 文件。

于 2017-03-28T08:57:08.737 回答