[英]Convert java to groovy
我正在嘗試在groovy中運行以下Java代碼。 我相信我已經正確導入了該類並將必要的jar文件添加到了類路徑中。 但是,我仍然遇到編譯錯誤。
Java代碼:
package com.tradeking;
this.class.classLoader.rootLoader.addURL( new URL("file:///C:/Program Files (x86)/Groovy/Groovy-2.4.0/lib/commons-codec-1.10.jar") )
this.class.classLoader.rootLoader.addURL( new URL("file:///C:/Program Files (x86)/Groovy/Groovy-2.4.0/lib/scribe-1.3.7.jar") )
import org.scribe.builder.*;
import org.scribe.model.*;
import org.scribe.oauth.*;
import org.scribe.builder.api.DefaultApi10a;
import org.scribe.model.Token;
public class TradeKingApi extends DefaultApi10a
{
private static final String CONSUMER_KEY = "***";
private static final String CONSUMER_SECRET = "***";
private static final String OAUTH_TOKEN = "***";
private static final String OAUTH_TOKEN_SECRET = "***";
private static final String PROTECTED_RESOURCE_URL = "https://api.tradeking.com/v1/market/ext/quotes.xml";
public static void main(String[] args)
{
OAuthService service = new ServiceBuilder()
.provider(TradeKingApi.class)
.apiKey("***")
.apiSecret("***")
.build();
Token accessToken = new Token("***", "***");
}
}
運行以上命令時,出現以下錯誤:
3 compilation errors:
Abstract method 'java.lang.String getRequestTokenEndpoint()' is not implemented but a method of the same name but different return type is defined: method 'java.lang.String getRequestTokenEndpoint()'
at line: -1, column: -1
Abstract method 'java.lang.String getAuthorizationUrl(org.scribe.model.Token)' is not implemented but a method of the same name but different return type is defined: method 'java.lang.String getAuthorizationUrl(org.scribe.model.Token)'
at line: -1, column: -1
Abstract method 'java.lang.String getAccessTokenEndpoint()' is not implemented but a method of the same name but different return type is defined: method 'java.lang.String getAccessTokenEndpoint()'
at line: -1, column: -1
感謝您的任何提示或建議。
根據https://github.com/fernandezpablo85/scribe-java/blob/master/src/main/java/org/scribe/builder/api/DefaultApi10a.java
您必須正確導入此類。
看起來您在編譯時遇到類路徑問題。
這意味着編譯器找不到您要擴展DefaultApi10a
的類的定義。
一個快速的Google告訴我,該類在org.scribe.builder
包中,您已經在該類的頂部導入了該包。
您需要將jar文件添加到構建環境的類路徑中,以使編譯器能夠解析已導入的類。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.