我正在尝试为AWS Translation运行一个基本示例,并且在运行程序时遇到错误。
我正在运行的代码如下: (不包括main / import语句):
AWSCredentialsProvider awsCreds = DefaultAWSCredentialsProviderChain.getInstance();
AWSTranslate translate = AmazonTranslateClient.standard()
.withCredentials(new AWSStaticCredentialsProvider(awsCreds)).withRegion(REGION).build();
TranslateTextRequest request = new TranslateTextRequest().withText("Hello, world").withSourceLanguageCode("en")
.withTargetLanguageCode("es");
TranslateTextResult result = translate.translateText(request);
System.out.println(result.getTranslatedText());
步骤:
mvn package
java -cp target/my-app-1.0-SNAPSHOT.jar com.mycompany.app.App
错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
AWSTranslate cannot be resolved to a type
The method standard() is undefined for the type AmazonTranslateClient
The constructor AWSStaticCredentialsProvider(AWSCredentialsProvider) is undefined
at com.mycompany.app.App.translatetry(App.java:35)
at com.mycompany.app.App.main(App.java:26)
我有一个Maven构建文件,其中包括:
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.327</version>
</dependency>
</dependencies>
和
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin </artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>