我尝试使用 Ant 编译 jsoup 源。我可以编译成功,但无法通过测试。这是过程:
jsoup 版本:1.6.3;蚂蚁版本:1.8.2
jsoup的源码在目录中
src/
我做了一个构建文件
src/build.xml
该文件包含
<project name="jsoup">
<target name="compile">
<mkdir dir="build/classes"/>
<javac srcdir="src" destdir="build/classes" includeantruntime="false"/>
</target>
<target name="jar">
<mkdir dir="build/jar"/>
<jar destfile="build/jar/jsoup.jar" basedir="build/classes">
<manifest>
<attribute name="Main-Class" value="StateTrace"/>
</manifest>
</jar>
</target>
<target name="run">
<!--<java jar="build/jar/jsoup.jar" input="htmls/index.html" fork="true"/>-->
<exec executable="java">
<arg value="-jar"/>
<arg value="build/jar/jsoup.jar"/>
<arg value="htmls/index.html"/>
</exec>
</target>
</project>
注:1.StateTrace.java是我自己的测试程序(如下);2. htmls/index.html 是StateTrace.java 的输入。
String html; // contains the content in htmls/index.html
...
try{
Document doc = Jsoup.parse(html);
}catch(IOException e){e.printStackTrace();}
然后我用 Ant 编译并运行它:
> ant compile
> ant jar
> ant run
在此之后,我得到了这样的错误:
run:
[exec] Exception in thread "main" java.lang.ExceptionInInitializerError
[exec] at org.jsoup.nodes.Entities$EscapeMode.<clinit>(Unknown Source)
[exec] at org.jsoup.nodes.Document$OutputSettings.<init>(Unknown Source)
[exec] at org.jsoup.nodes.Document.<init>(Unknown Source)
[exec] at org.jsoup.parser.TreeBuilder.initialiseParse(Unknown Source)
[exec] at org.jsoup.parser.TreeBuilder.parse(Unknown Source)
[exec] at org.jsoup.parser.HtmlTreeBuilder.parse(Unknown Source)
[exec] at org.jsoup.parser.Parser.parse(Unknown Source)
[exec] at org.jsoup.Jsoup.parse(Unknown Source)
[exec] at StateTrace.main(Unknown Source)
[exec] Caused by: java.lang.NullPointerException
[exec] at java.util.Properties$LineReader.readLine(Properties.java:418)
[exec] at java.util.Properties.load0(Properties.java:337)
[exec] at java.util.Properties.load(Properties.java:325)
[exec] at org.jsoup.nodes.Entities.loadEntities(Unknown Source)
[exec] at org.jsoup.nodes.Entities.<clinit>(Unknown Source)
[exec] ... 9 more
[exec] Result: 1
BUILD SUCCESSFUL
Total time: 0 seconds
但是,如果我手动编译了所有的 java 源代码,比如
javac src/org/jsoup/*.java src/org/jsoup/parser/*.java src/org/jsoup/examples/*.java src/org/jsoup/nodes/*.java src/org/jsoup/safety/*.java src/org/jsoup/select/*.java src/org/jsoup/helper/*.java
我可以成功编译并通过我的测试。
有什么线索吗?谢谢!