Java 获取非法访问错误

Java 获取非法访问错误,java,Java,当我使用此代码时,会出现以下错误: 2011-08-10 13:18:13.368::警告:异常 java.lang.IllegalAccessError:试图从org.mortbay.jetty.HttpURI类访问方法org.mortbay.util.Utf8StringBuffer。(I)V 代码: 这里有两个潜在的。请注意,您得到的是一个错误,而不是一个异常,因此这很有趣。您可以尝试使用-verbose运行JVM,以查看每个类从何处加载,查看是否使用一个类/jar进行编译,但意外地使用另

当我使用此代码时,会出现以下错误:

2011-08-10 13:18:13.368::警告:异常
java.lang.IllegalAccessError:试图从org.mortbay.jetty.HttpURI类访问方法org.mortbay.util.Utf8StringBuffer。(I)V

代码:

这里有两个潜在的。请注意,您得到的是一个错误,而不是一个异常,因此这很有趣。您可以尝试使用-verbose运行JVM,以查看每个类从何处加载,查看是否使用一个类/jar进行编译,但意外地使用另一个类/jar进行编译

从错误中还可以注意到,包与“org.mortbay.util”和“org.mortbay.jetty”略有不同,因此UTF8StringBuffer构造函数需要更加可见。但是,通常情况下,编译器会捕捉到这一点

我意识到这肯定不是一个完整的答案,但至少有几个地方可以开始寻找

package com.google.api.client.sample.docs.v3;

import com.google.api.client.auth.oauth.OAuthCredentialsResponse;
import com.google.api.client.auth.oauth.OAuthHmacSigner;
import com.google.api.client.auth.oauth.OAuthParameters;
import com.google.api.client.googleapis.auth.oauth.GoogleOAuthAuthorizeTemporaryTokenUrl;
import com.google.api.client.googleapis.auth.oauth.GoogleOAuthGetAccessToken;
import com.google.api.client.googleapis.auth.oauth.GoogleOAuthGetTemporaryToken;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.sample.docs.v3.model.DocsUrl;
import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.net.URI;

public class Auth {

    private static final String APP_NAME ="Google Documents List Data API Java Client Sample";

    private static OAuthHmacSigner signer;

    private static OAuthCredentialsResponse credentials;

    static void authorize(HttpTransport transport) throws Exception {
        // callback server
        LoginCallbackServer callbackServer = null;
        String verifier = null;
        String tempToken = null;
        try {

            callbackServer = new LoginCallbackServer();
            callbackServer.start();
            // temporary token
            GoogleOAuthGetTemporaryToken temporaryToken =new GoogleOAuthGetTemporaryToken();
            signer = new OAuthHmacSigner();
            signer.clientSharedSecret = "anonymous";
            temporaryToken.signer = signer;
            temporaryToken.consumerKey = "in.gappsdemo.in";
            //temporaryToken.scope ="https://apps-apis.google.com/a/feeds/user/";
            temporaryToken.scope = DocsUrl.ROOT_URL;
            temporaryToken.displayName = APP_NAME;
            temporaryToken.callback = callbackServer.getCallbackUrl();
            System.out.println("temporaryToken.callback: "+temporaryToken.callback);
            OAuthCredentialsResponse tempCredentials = temporaryToken.execute();
            signer.tokenSharedSecret = tempCredentials.tokenSecret;
            System.out.println("signer.tokenSharedSecret: " + signer.tokenSharedSecret);
            // authorization URL
            GoogleOAuthAuthorizeTemporaryTokenUrl authorizeUrl =new GoogleOAuthAuthorizeTemporaryTokenUrl();
            authorizeUrl.temporaryToken = tempToken = tempCredentials.token;
            String authorizationUrl = authorizeUrl.build();
            System.out.println("Go to this authorizationUrl: " + authorizationUrl);
            // launch in browser
            boolean browsed = false;
            if (Desktop.isDesktopSupported()) {
                Desktop desktop = Desktop.getDesktop();
                if (desktop.isSupported(Action.BROWSE)) {
                    System.out.println("In if browsed condition:");
                    desktop.browse(URI.create(authorizationUrl));
                    browsed = true;
                }
            }
            if (!browsed) {
                String browser = "google-chrome";
                Runtime.getRuntime().exec(new String[] {browser, authorizationUrl});
                System.out.println("In if !browsed condition1:");
            }
            System.out.println("tempToken: "+tempToken);
            verifier = callbackServer.waitForVerifier(tempToken);
            System.out.println("GoogleOAuthGetAccessToken: ");
        } finally {
            System.out.println("server Stop:");
            if (callbackServer != null) {
                System.out.println("server Stop:");
                callbackServer.stop();
            }
        }
        System.out.println("GoogleOAuthGetAccessToken: ");
        GoogleOAuthGetAccessToken accessToken = new GoogleOAuthGetAccessToken();
        accessToken.temporaryToken = tempToken;
        accessToken.signer = signer;
        accessToken.consumerKey = "in.gappsdemo.in";
        accessToken.verifier = verifier;
        credentials = accessToken.execute();
        signer.tokenSharedSecret = credentials.tokenSecret;
        System.out.println("signer.tokenSharedSecret: ");
        createOAuthParameters().signRequestsUsingAuthorizationHeader(transport);
    }

    static void revoke() {
        if (credentials != null) {
            try {
                GoogleOAuthGetAccessToken.revokeAccessToken(createOAuthParameters());
            } catch (Exception e) {
                e.printStackTrace(System.err);
            }
        }
    }

    private static OAuthParameters createOAuthParameters() {
        OAuthParameters authorizer = new OAuthParameters();
        authorizer.consumerKey = "in.gappsdemo.in";
        authorizer.signer = signer;
        authorizer.token = credentials.token;
        return authorizer;
    }
}