How to compile jsoup through Ant?
- by JackWM
I tried to use Ant to compile the jsoup source. I can compile successfully, but cannot pass the test. Here is the process:
jsoup version: 1.6.3 ; Ant version: 1.8.2
the source of jsoup is in the directory
src/
I made a build file
src/build.xml
This file contains
<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>
Note:
1. StateTrace.java is my own test program; 2. htmls/index.html is the input to StateTrace.java.
Then I compile and run it with Ant:
> ant compile
> ant jar
> ant run
After this, I got err like:
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
However, if I manually compiled all the java source, like
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
I could compile successfully and pass my test.
Any clue? Thanks!