我有编写以下代码来读取“struts.xml”(struts2 配置文件)。
static main(args) {
String path = /struts.xml/
String timestamp = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date())
String csvName = "struts2-" + timestamp + ".csv"
Node struts = new XmlParser().parse(new File(path))
FileWriter writer = new FileWriter(new File(csvName))
writer.write "#,package,extends,action,method,class\n"
int counter = 1;
struts.package.each { pck ->
pck.action.each { action ->
writer.write("${counter++},${pck.@name},${pck.@extends},${action.@name},${Utils.preventNull(action.@method)},${action.@class}\n")
}
}
writer.close()
println("File Processed")
}
struts.xml 在其中定义了以下文档类型。
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
当我从 struts.xml 中删除这一行时,代码运行完美。否则它会给出以下异常。
Exception in thread "main" java.net.UnknownHostException: struts.apache.org
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:234)
at java.net.Socket.connect(Socket.java:551)
at java.net.Socket.connect(Socket.java:501)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:403)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:521)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:246)
at sun.net.www.http.HttpClient.New(HttpClient.java:320)
at sun.net.www.http.HttpClient.New(HttpClient.java:337)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:838)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:790)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:715)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:959)
at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startDTDEntity(Unknown Source)
at org.apache.xerces.impl.XMLDTDScannerImpl.setInputSource(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl$DTDDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at groovy.util.XmlParser.parse(XmlParser.java:118)
at groovy.util.XmlParser$parse.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at demo.main(Struts2ConfigurationReader.groovy:14)
我错过了什么?