【发布时间】:2015-04-08 08:56:06
【问题描述】:
像这样来自 gwt 的 SecureDispatchService 类:
@RemoteServiceRelativePath("dispatch")
public interface SecureDispatchService extends RemoteService {
Result execute( String sessionId, Action<?> action ) throws DispatchException;
}
RemoteServiceRelativePath:
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface RemoteServiceRelativePath {
/**
* The relative path for the {@link RemoteService} implementation.
*
* @return relative path for the {@link RemoteService} implementation
*/
String value();
}
测试代码很简单:
package com.name.sbts.wbts.sm;
import net.customware.gwt.dispatch.client.secure.SecureDispatchService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
public class TestClass {
public static void main(String[] args) {
Class c = SecureDispatchService.class;
System.out.println(c.getAnnotation(RemoteServiceRelativePath.class));
System.out.println(c.getAnnotations().length);
}
}
但结果是不想要的:
null
0
我在 Eclipse 中使用 JRE1.7 运行此代码
SecureDispatchService 在这个来自 google 的 jar 中:
gwt-dispatch-1.2.0.jar
我使用mvn eclipse:eclipse 来生成项目。
这个jar文件作为eclipse项目的引用库,真实路径在我的.m2/repostory中。
【问题讨论】:
-
包含注解的类文件必须在正在运行的应用程序的类路径中。否则,JVM 将在加载类时静默删除注释,从而导致您看到的行为。也许这是你的问题? (如果是这样,我会将我的评论升级为答案。)
-
也许是这个原因,但是你知道如何解决这个问题吗? SecureDispatchService 类由 google 提供,它位于 jar 文件中:gwt-dispatch-1.2.0.jar。我在eclipse中使用mvn eclipse:eclipse生成项目,直接在eclipse中运行应用。
-
我也尝试将此jar文件添加到我的系统变量的CLASS_PATH,但似乎不起作用。
-
你不应该使用
mvn eclipse:eclipse来eclipsify你的项目。而是使用 M2E 插件。此外,您的 POM 应该简单地将库作为依赖项。就是这样。 (永远不要操作 CLASS_PATH 环境变量。) -
@Seelenvirtuose,感谢您的帮助。虽然它并没有真正解决这个问题。
标签: java eclipse gwt annotations gwt-rpc