GWT AutoBean类别

时间:2013-04-18 08:26:05

标签: gwt autobean

我正在尝试让AutoBean中的@Category(类)工作。

我有一个简单的工厂

import com.google.web.bindery.autobean.shared.AutoBean;
import com.google.web.bindery.autobean.shared.AutoBeanFactory.Category;

@Category(TestCategory.class)
public interface TestFactory {
    AutoBean<Test> test();
}

和类别

导入com.google.web.bindery.autobean.shared.AutoBean;

public class TestCategory {
    public static String asString(AutoBean<Test> instance) {
        return "as a string";
    }
}

和测试界面。

public interface Test {
    String getValue();
    void setValue(String value);
    String asString();
}

所有三个人都在同一个包中。

当我尝试编译GWT项目时,我收到以下错误消息

 [java]    Resolving com.mycompany.my_gwt_project.client.test.TestFactory
 [java]       Found type 'com.mycompany.my_gwt_project.client.test.TestFactory'
 [java]          [ERROR] Annotation error: cannot resolve com.mycompany.my_gwt_project.client.test.TestCategory
 [java]    java.lang.ClassNotFoundException: com.mycompany.my_gwt_project.client.test.TestCategory
 [java]     at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
 [java]     at java.security.AccessController.doPrivileged(Native Method)
 [java]     at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
 [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
 [java]     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
 [java]     at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
 [java]     at java.lang.Class.forName0(Native Method)
 [java]     at java.lang.Class.forName(Class.java:249)
 [java]     at com.google.gwt.dev.javac.TypeOracleMediator.resolveAnnotationValue(TypeOracleMediator.java:750)
 [java]     at com.google.gwt.dev.javac.TypeOracleMediator.resolveAnnotationValue(TypeOracleMediator.java:689)
 [java]     at com.google.gwt.dev.javac.TypeOracleMediator.createAnnotation(TypeOracleMediator.java:498)
 [java]     at com.google.gwt.dev.javac.TypeOracleMediator.resolveAnnotation(TypeOracleMediator.java:648)
 [java]     at com.google.gwt.dev.javac.TypeOracleMediator.resolveAnnotations(TypeOracleMediator.java:663)
 [java]     at com.google.gwt.dev.javac.TypeOracleMediator.resolveClass(TypeOracleMediator.java:809)
 [java]     at com.google.gwt.dev.javac.TypeOracleMediator.addNewTypes(TypeOracleMediator.java:439)
 [java]     at com.google.gwt.dev.javac.TypeOracleMediatorFromSource.addNewUnits(TypeOracleMediatorFromSource.java:52)
 [java]     at com.google.gwt.dev.javac.CompilationState.assimilateUnits(CompilationState.java:164)
 [java]     at com.google.gwt.dev.javac.CompilationState.<init>(CompilationState.java:82)
 [java]     at com.google.gwt.dev.javac.CompilationStateBuilder.doBuildFrom(CompilationStateBuilder.java:466)
 [java]     at com.google.gwt.dev.javac.CompilationStateBuilder.buildFrom(CompilationStateBuilder.java:388)
 [java]     at com.google.gwt.dev.cfg.ModuleDef.getCompilationState(ModuleDef.java:373)
 [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:246)
 [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:229)
 [java]     at com.google.gwt.dev.Precompile.precompile(Precompile.java:141)
 [java]     at com.google.gwt.dev.Compiler.run(Compiler.java:232)
 [java]     at com.google.gwt.dev.Compiler.run(Compiler.java:198)
 [java]     at com.google.gwt.dev.Compiler$1.run(Compiler.java:170)
 [java]     at com.google.gwt.dev.CompileTaskRunner.doRun(CompileTaskRunner.java:88)
 [java]     at com.google.gwt.dev.CompileTaskRunner.runWithAppropriateLogger(CompileTaskRunner.java:82)
 [java]     at com.google.gwt.dev.Compiler.main(Compiler.java:177)
 [java]          [ERROR] Annotation error: expected class java.lang.Class, got null

有人有线索吗?

1 个答案:

答案 0 :(得分:0)

你必须javac你的类并将它们包含在DevMode的类路径中。

遗憾的是,这是GWT当前设计的已知限制:https://code.google.com/p/google-web-toolkit/issues/detail?id=7602