eclipse + maven + org.glassfish.jersey 创建 webapi

org.glassfish.jersey 和 com.sun.jersey 的区别是,jersy version 2 之前是 com.sun.jersy, 之后改名为 org.glassfish.jersey, 所以想用 jersey 新版本就用 org.glassfish.jersey;

创建

eclipse + maven + org.glassfish.jersey 创建 webapi_第1张图片

支持返回 json 对象

pom


    
        org.glassfish.jersey.media
        jersey-media-json-jackson
        2.25.1
    
    @GET 
    @Produces(MediaType.APPLICATION_JSON)
    public UserInfo getIt() {
        UserInfo user =  new UserInfo();
        user.setId("1");
        user.setName("grissom");
        return user;
    }
错误: Exception in thread "main" java.lang.NoSuchMethodError: org.glassfish.jersey.CommonProperties.getValue(Ljava/util/Map;Ljavax/ws/rs/RuntimeType;Ljava/lang/String;Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object; ,修改jersey 版本号,和 json 一致
    
        2.25.1
        UTF-8
    
错误: org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor aroundWriteTo

去掉或注释下面这段

        
错误 Caused by: java.lang.ClassNotFoundException: org.glassfish.jersey.client.ClientConfig ,添加
        
            org.glassfish.jersey.core
            jersey-client
            2.25.1
            provided
        
错误 Exception in thread "main" java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor ,添加
    
            asm
            asm
            3.3.1
        

我的 demo pom:



    4.0.0

    com.easymerylife.member
    member
    jar
    0.0.1-SNAPSHOT
    member

    
        
            
                org.glassfish.jersey
                jersey-bom
                ${jersey.version}
                pom
                import
            
        
    

    
        
            org.glassfish.jersey.containers
            jersey-container-grizzly2-http
        
        
            org.glassfish.jersey.media
            jersey-media-json-jackson
            2.25.1
        
        
            junit
            junit
            4.9
            test
        
        
            org.glassfish.jersey.core
            jersey-client
            2.25.1
            provided
        
        
            asm
            asm
            3.3.1
        
    

    
        
            
                org.apache.maven.plugins
                maven-compiler-plugin
                2.5.1
                true
                
                    1.6
                    1.6
                
            
            
                org.codehaus.mojo
                exec-maven-plugin
                1.2.1
                
                    
                        
                            java
                        
                    
                
                
                    com.easymerylife.member.member.Main
                
            
        
    

    
        2.25.1
        UTF-8
    


你可能感兴趣的:(eclipse + maven + org.glassfish.jersey 创建 webapi)