Java NoClassDefFoundError:com/google/common/reflect/TypeToken
我一直在使用api。该API是Mailchimp API的Java包装器,具有maven依赖性Java NoClassDefFoundError:com/google/common/reflect/TypeToken,java,intellij-idea,google-api,noclassdeffounderror,typetoken,Java,Intellij Idea,Google Api,Noclassdeffounderror,Typetoken,我一直在使用api。该API是Mailchimp API的Java包装器,具有maven依赖性 <dependency> <groupId>com.ecwid</groupId> <artifactId>ecwid-mailchimp</artifactId> <version>2.0.1.0</version> </dependency> 下面是updateAllUnSub
<dependency>
<groupId>com.ecwid</groupId>
<artifactId>ecwid-mailchimp</artifactId>
<version>2.0.1.0</version>
</dependency>
下面是updateAllUnSubscribedEmails的代码
public void updateAllUnSubscribedEmails( Date lastRunDate, String brandCode,Logger logger){
logger.log(Level.SEVERE, "Entering mail chimp subscription processor in boardwalk for :" + brandCode);
logger.log(Level.SEVERE, "Last run date is :" + lastRunDate);
System.out.println("Entering mail chimp subscription processor in boardwalk for :" + brandCode);
try {
MailChimpSubscriptionDAO subscriptionDAO = MailChimpSubscriptionDAO.INSTANCE;
MailChimpSubscription subscription= subscriptionDAO.getMailChimpSubscriptionByBrandCode(brandCode);
logger.log(Level.SEVERE,"Subscription object is :"+ subscription);
**ListMembersMethod listMembersMethod= new ListMembersMethod();**
logger.log(Level.SEVERE,"listMembersMethod object is :"+ listMembersMethod);
listMembersMethod.status= MemberStatus.unsubscribed;
logger.log(Level.SEVERE,"listMembersMethod.status object is :"+ listMembersMethod.status);
listMembersMethod.apikey=mailChimpApiKey;
logger.log(Level.SEVERE,"listMembersMethod.apikey object is :"+ listMembersMethod.apikey);
listMembersMethod.id=subscription.getEmailListId();
logger.log(Level.SEVERE,"listMembersMethod.id object is :"+ listMembersMethod.id);
listMembersMethod.since= lastRunDate;
.
.
.
.
} catch (IOException e) {
e.printStackTrace();
System.out.println(e.getMessage());
logger.log(Level.SEVERE, e.getMessage());
} catch (MailChimpException e) {
e.printStackTrace();
System.out.println(e.getMessage());
logger.log(Level.SEVERE, e.getMessage());
}
catch (Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
logger.log(Level.SEVERE, e.getMessage());
}
finally {
logger.log(Level.SEVERE,"Finally block ...Try catch block ended");
}
logger.log(Level.SEVERE,"After finally Try catch block without exception ");
}
代码在此行停止工作:
ListMembersMethod ListMembersMethod=新ListMembersMethod()强>
它甚至根本不进入异常块。只到最后一个街区
这是Intelij IDEA为类ListMembersMethod生成的代码:
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.ecwid.mailchimp.method.v1_3.list;
import com.ecwid.mailchimp.MailChimpAPIVersion;
import com.ecwid.mailchimp.MailChimpMethod.Method;
import com.ecwid.mailchimp.MailChimpObject.Field;
import com.ecwid.mailchimp.method.v1_3.list.HasListIdMethod;
import com.ecwid.mailchimp.method.v1_3.list.ListMembersResult;
import com.ecwid.mailchimp.method.v1_3.list.MemberStatus;
import java.util.Date;
@Method(
name = "listMembers",
version = MailChimpAPIVersion.v1_3
)
public class ListMembersMethod extends HasListIdMethod<ListMembersResult> {
@Field
public MemberStatus status;
@Field
public Date since;
@Field
public Integer start;
@Field
public Integer limit;
public ListMembersMethod() {
}
}
Intelij Idea has also generated the following code for hasHasListIdMethod :
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.ecwid.mailchimp.method.v1_3.list;
import com.ecwid.mailchimp.MailChimpMethod;
import com.ecwid.mailchimp.MailChimpObject.Field;
public abstract class HasListIdMethod<R> extends MailChimpMethod<R> {
@Field
public String id;
public HasListIdMethod() {
}
}
//
//IntelliJ IDEA从.class文件重新创建的源代码
//(由Fernflower反编译器提供动力)
//
包com.ecwid.mailchimp.method.v1_3.list;
导入com.ecwid.mailchimp.mailchimp版本;
导入com.ecwid.mailchimp.mailchimp.Method;
导入com.ecwid.mailchimp.MailChimpObject.Field;
导入com.ecwid.mailchimp.method.v1_3.list.HasListIdMethod;
导入com.ecwid.mailchimp.method.v1_3.list.ListMembersResult;
导入com.ecwid.mailchimp.method.v1_3.list.MemberStatus;
导入java.util.Date;
@方法(
name=“listMembers”,
版本=MailChimpAPIVersion.v1_3
)
公共类ListMembersMethod扩展了HasListIdMethod{
@场
公共会员身份;
@场
自发布日期起;
@场
公共整数启动;
@场
公共整数限制;
公共列表成员方法(){
}
}
Intelij Idea还为hasHasListIdMethod生成了以下代码:
//
//IntelliJ IDEA从.class文件重新创建的源代码
//(由Fernflower反编译器提供动力)
//
包com.ecwid.mailchimp.method.v1_3.list;
导入com.ecwid.mailchimp.mailchimp方法;
导入com.ecwid.mailchimp.MailChimpObject.Field;
公共抽象类HasListIdMethod扩展了MailChimp方法{
@场
公共字符串id;
公共HasListIdMethod(){
}
}
MailChimpMethod包含以下代码,其中包含TypeToken
:
//
//IntelliJ IDEA从.class文件重新创建的源代码
//(由Fernflower反编译器提供动力)
//
包com.ecwid.mailchimp;
导入com.ecwid.mailchimp.mailchimp版本;
导入com.ecwid.mailchimp.mailchimp对象;
导入com.ecwid.mailchimp.MailChimpObject.Field;
导入com.google.common.reflect.TypeToken;
导入java.lang.annotation.Documented;
导入java.lang.annotation.ElementType;
导入java.lang.annotation.Retention;
导入java.lang.annotation.RetentionPolicy;
导入java.lang.annotation.Target;
导入java.lang.reflect.GenericArrayType;
导入java.lang.reflect.ParameterizedType;
导入java.lang.reflect.Type;
公共抽象类MailChimpMethod扩展了MailChimpObject{
private final TypeToken resultTypeToken=新的TypeToken(this.getClass()){
};
@场
公钥;
公共方法(){
}
公共方法getMetaInfo(){
for(类c=this.getClass();c!=null;c=c.getSuperclass()){
MailChimpMethod.MethodA=(MailChimpMethod.Method)c.getAnnotation(MailChimpMethod.Method.class);
如果(a!=null){
返回a;
}
}
抛出新的IllegalArgumentException(“无论是“+this.getClass()+”还是它的超类都没有用“+MailChimpMethod.Method.class”注释);
}
公共最终类型getResultType(){
Type Type=this.resultTypeToken.getType();
if(!(类的类型instanceof)和&!(参数化类型的类型instanceof)和&!(genericaraytype的类型instanceof)){
抛出新的IllegalArgumentException(“无法解析结果类型:“+this.resultTypeToken”);
}否则{
返回类型;
}
}
@记录
@保留(RetentionPolicy.RUNTIME)
@目标({ElementType.TYPE})
公共@接口方法{
邮件版本();
字符串名();
}
}
我非常感谢你在这方面的帮助。无法确定修复方法。MailChimp API包装器2.0.1.0依赖于Guava 16.0.1(请参阅)。
com.google.common.reflect.TypeToken
类是Guava16.0.1的一部分(请参阅)
你是否使用Maven来构建你的项目?如果是这样,你能编译/测试你的代码而不出问题吗?该项目是否下载了番石榴?运行mvn dependency:tree-Dverbose时,您看到了什么?我花了一些时间,但我发现了问题。我在从事两个独立的项目,它们依赖于MailChimp API。然而,我对其中一个项目没有maven依赖,这就是问题的根源 因此,在这两个项目中都包含了maven依赖项,而且它工作得很有魅力
<dependency>
<groupId>com.ecwid</groupId>
<artifactId>ecwid-mailchimp</artifactId>
<version>2.0.1.0</version>
</dependency>
com.ecwid
埃克维德邮件黑猩猩
2.0.1.0
感谢您的回复@Freek。我发现了问题。请看答案。这应该是公认的答案。一种较旧的番石榴被一些自由党拉了进来。排除它。谢谢你,弗里克!
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//
package com.ecwid.mailchimp;
import com.ecwid.mailchimp.MailChimpAPIVersion;
import com.ecwid.mailchimp.MailChimpObject;
import com.ecwid.mailchimp.MailChimpObject.Field;
import com.google.common.reflect.TypeToken;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.GenericArrayType;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
public abstract class MailChimpMethod<R> extends MailChimpObject {
private final TypeToken<R> resultTypeToken = new TypeToken(this.getClass()) {
};
@Field
public String apikey;
public MailChimpMethod() {
}
public final MailChimpMethod.Method getMetaInfo() {
for(Class c = this.getClass(); c != null; c = c.getSuperclass()) {
MailChimpMethod.Method a = (MailChimpMethod.Method)c.getAnnotation(MailChimpMethod.Method.class);
if(a != null) {
return a;
}
}
throw new IllegalArgumentException("Neither " + this.getClass() + " nor its superclasses are annotated with " + MailChimpMethod.Method.class);
}
public final Type getResultType() {
Type type = this.resultTypeToken.getType();
if(!(type instanceof Class) && !(type instanceof ParameterizedType) && !(type instanceof GenericArrayType)) {
throw new IllegalArgumentException("Cannot resolve result type: " + this.resultTypeToken);
} else {
return type;
}
}
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
public @interface Method {
MailChimpAPIVersion version();
String name();
}
}
<dependency>
<groupId>com.ecwid</groupId>
<artifactId>ecwid-mailchimp</artifactId>
<version>2.0.1.0</version>
</dependency>