0
我開始在groovy中編寫一些腳本。我編寫了這個腳本,它基本上解析了一個html頁面,並對這些數據做了一些處理。IllegalAccessException試圖訪問StringHashMap - Groovy
現在,我使用HTTPBuilder來執行http請求。每當我試圖執行這種要求,我得到這個錯誤:
Caught: java.lang.IllegalAccessError: tried to access class groovyx.net.http.StringHashMap from class groovyx.net.http.HTTPBuilder
java.lang.IllegalAccessError: tried to access class groovyx.net.http.StringHashMap from class groovyx.net.http.HTTPBuilder
at groovyx.net.http.HTTPBuilder.<init>(HTTPBuilder.java:177)
at groovyx.net.http.HTTPBuilder.<init>(HTTPBuilder.java:218)
at Main$_main_closure1.doCall(Main.groovy:30)
at Main.main(Main.groovy:24)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:143)
這裏是主類的代碼:
// Grap HTTPBuilder component from maven repository
@Grab(group='org.codehaus.groovy.modules.http-builder',
module='http-builder', version='0.5.2')
// import of HttpBuilder related stuff
import groovyx.net.http.*
import parsers.Parser
import parsers.WuantoParser
import parsers.Row
class Main {
static mapOfParsers = [:]
static void main(args) {
List<Row> results = new ArrayList<>()
// Initiating the parsers for the ebay-keywords websites
println "Initiating Parsers..."
initiateParsers()
println "Parsing Websites..."
mapOfParsers.each { key, parser ->
switch (key) {
case Constants.Parsers.WUANTO_PARSER:
println "Parsing Url: $Constants.Url.WUANTO_ROOT_CAT_URL"
println "Retrieving Html Content..."
def http = new HTTPBuilder(Constants.Url.WUANTO_ROOT_CAT_URL)
def html = http.get([:])
println "Parsing Html Content..."
results.addAll(((Parser) parser).parseHtml(html))
break
}
}
results.each {
println it
}
}
static void initiateParsers() {
mapOfParsers.put(Constants.Parsers.WUANTO_PARSER , new WuantoParser())
}
static void writeToFile(List<Row> rows) {
File file = "output.txt"
rows.each {
file.write it.toString()
}
}
}