我是Maven的新手,我正在尝试编写一小段Java代码。我包括一些包裹。 Maven似乎下载了我预期需要的所有内容,但是当涉及编译时,它无法说它找不到特定的类。错误进一步表明它无法找到我的任何导入。有人能告诉我我错过了什么吗?
这是我的代码:
package in.myscratchpad.app;
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.profile.ProfileCredentialsProvider;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;
import com.amazonaws.services.dynamodb.AmazonDynamoDBClient;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
AmazonDynamoDBClientBuilder builder = AmazonDBClientBuilder.standard();
}
}
这是我的pom.xml:
<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>in.myscratchpad.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>my-app</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>in.myscratchpad.app.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.60</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</project>
这些是我得到的错误:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project my-app: Compilation failure: Compilation failure:
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[3,21] package com.amazonaws does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[4,21] package com.amazonaws does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[5,26] package com.amazonaws.auth does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[6,34] package com.amazonaws.auth.profile does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[7,29] package com.amazonaws.regions does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[8,29] package com.amazonaws.regions does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[9,39] package com.amazonaws.services.dynamodb does not exist
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[20,9] cannot find symbol
[ERROR] symbol: class AmazonDynamoDBClientBuilder
[ERROR] location: class in.myscratchpad.app.App
[ERROR] /home/ec2-user/projects/kinesisProducer1/my-app/src/main/java/in/myscratchpad/app/App.java:[20,47] cannot find symbol
[ERROR] symbol: variable AmazonDBClientBuilder
[ERROR] location: class in.myscratchpad.app.App
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
当我简单地保留没有AWS包的Hello,World代码时,它工作正常,当我尝试构建服务客户端时,我得到了这些错误。
答案 0 :(得分:0)
它说
...cannot find symbol
[ERROR] symbol: variable AmazonDBClientBuilder
[ERROR] location: class in.myscratchpad.app.App
哪些接缝可以清楚地解释它可以编译in.myscratchpad.app.App
,因为它中有一个符号(即AmazonDBClientBuilder
)无法找到!
我不知道这个课程是针对什么的,但鉴于此
AmazonDBClientBuilder
类AmazonDynamoDBClientBuilder
类型不是代码中的拼写错误,您应该使用AmazonDynamoDBClientBuilder.standard()
代替吗?