0

I have a Maven project in Eclipse created through m2e. It obtains client libraries from a project on GitHub called alternator. The classes seem to be imported fine, in my project, but on running them, it shows a NoClassDefFound error. Here's the code and the error:

Code:

public class Main{

private AlternatorDBClient client;
private DynamoDBMapper mapper;
private AlternatorDB db;

public static void main(String args[]) throws Exception{
    new Main().run();
}

public void run() throws Exception {
    this.client = new AlternatorDBClient();
    this.mapper = new DynamoDBMapper(this.client);
    this.db = new AlternatorDB().start();
}

}

Error:

Exception in thread "main" java.lang.NoClassDefFoundError: com/michelboudreau/alternator/AlternatorDBClient
at Main.run(Main.java:17)
at Main.main(Main.java:13)
Caused by: java.lang.ClassNotFoundException: com.michelboudreau.alternator.AlternatorDBClient
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 2 more
4

1 回答 1

2

该类AlternatorDBClient正在导入一个或多个不在您的类路径中的类:

import com.amazonaws.*;
import com.amazonaws.handlers.HandlerChainFactory;
import com.amazonaws.http.ExecutionContext;
import com.amazonaws.http.HttpResponseHandler;
import com.amazonaws.http.JsonErrorResponseHandler;
import com.amazonaws.http.JsonResponseHandler;
import com.amazonaws.services.dynamodb.AmazonDynamoDB;
import com.amazonaws.services.dynamodb.model.*;
import com.amazonaws.services.dynamodb.model.transform.*;
import com.amazonaws.transform.JsonErrorUnmarshaller;
import com.amazonaws.transform.JsonUnmarshallerContext;
import com.amazonaws.transform.Unmarshaller;
import com.amazonaws.util.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

你不知何故失踪了:

 <dependency>
   <groupId>com.amazonaws</groupId>
   <artifactId>aws-java-sdk</artifactId>
 </dependency>

作为项目 pom 中的依赖项。正如 AlexR 所说,请发布您的 pom。

于 2013-05-26T13:05:19.047 回答