Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java class.getAnnotation和getAnnotations不';我不能正常工作_Java_Eclipse_Gwt_Annotations_Gwt Rpc - Fatal编程技术网

Java class.getAnnotation和getAnnotations不';我不能正常工作

Java class.getAnnotation和getAnnotations不';我不能正常工作,java,eclipse,gwt,annotations,gwt-rpc,Java,Eclipse,Gwt,Annotations,Gwt Rpc,来自gwt的类SecureDispatchService,如下所示: @RemoteServiceRelativePath("dispatch") public interface SecureDispatchService extends RemoteService { Result execute( String sessionId, Action<?> action ) throws DispatchException; } 测试代码非常简单: package com

来自gwt的类
SecureDispatchService
,如下所示:

@RemoteServiceRelativePath("dispatch")
public interface SecureDispatchService extends RemoteService {
    Result execute( String sessionId, Action<?> action ) throws DispatchException;
}
测试代码非常简单:

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
位于谷歌提供的这个jar中:

gwt-dispatch-1.2.0.jar
我使用
mvneclipse:eclipse
生成项目。
此jar文件作为eclipse项目的引用库,其实际路径在my.m2/repostory中。

之所以发生这种情况,是因为
gwt dispatch
项目是使用旧的
gwt user
依赖项(gwt版本
2.0.4
)编译的。在此版本的gwt中,注释上没有注释,因此运行时无法使用
RemoteServiceRelativePath
注释。

包含注释的类文件必须位于正在运行的应用程序的类路径中。否则,JVM将在加载类时无声地删除注释,这将导致您看到的行为。也许这是你的问题?(如果是这样,我会将我的评论升级为回答。)也许这就是原因,但你知道如何解决这个问题吗?SecureDispatchService类由google提供,它位于一个jar文件中:gwt-dispatch-1.2.0.jar。我使用mvn eclipse:eclipse在eclipse中生成项目,并在eclipse中直接运行应用程序。我还尝试将此jar文件添加到我的系统变量的CLASS_PATH中,但似乎不起作用。您不应该使用
mvn eclipse:eclipse
使您的项目黯然失色。相反,使用插件来实现这一点。此外,POM应该将库作为依赖项。就这样。(永远不应该操作CLASS_PATH环境变量。)@Seelenvirtuose,谢谢您的帮助。虽然它并没有真正解决这个问题。旧信息存储在哪里,我的意思是,如果在RemoteServiceRelativePath没有@Retention(RetentionPolicy.RUNTIME)的情况下编译gwt-dispatch-1.2.0.jar,我机器上的JVM应该知道这一点,并使用这些过时的数据,但在我的环境中,只有gwt-user-2.7.0。jar@JerryZhang:您正在检查
SecureDispatchService
类,它没有关于
RemoteServiceRelativePath
注释的信息,因为它是用旧版本编译的。是的,我理解该语句,但是问题是:
gwt-dispatch-1.2.0.jar
是否仍然保存着
gwt-user-2.0.4.jar
中的信息,因此jvm可能会查找到
remoteServiceRelativePath
的错误类细节@JerryZhang:是的,类保存着关于其注释的信息。如果在文本编辑器中打开
SecureDispatchService
类文件,则应该会看到类似于
RuntimeInvisibleNotations
的内容。是的,我在txt打开的类中看到了它。你知道我可以绕过这个问题,重新编译本地版本的
gwt dispatch
gwt-dispatch-1.2.0.jar