我正在尝试使用勺子进行流程注释。我按照示例(http://spoon.gforge.inria.fr/Doc/Basic#toc3)使用Ant运行勺子(因为勺子不适用于当前版本的Eclipse。
<?xml version="1.0"?>
<project name="TestBound" default="main" basedir=".">
<!-- Sets variables which can later be used. -->
<property name="src.dir" value="src" />
<property name="build.dir" value="bin" />
<property name="dist.dir" value="dist" />
<property name="extlib.dir" value ="D:\Java_Lib\Libs" />
<path id="build.classpath">
<pathelement location="${extlib.dir}\spoon-core-1.5-jar-with-dependencies.jar" />
<pathelement location="${extlib.dir}\SpoonTest.jar" />
</path>
<!-- define spoon task -->
<taskdef name="spoon" classname="spoon.SpoonTask" classpathref= "build.classpath"/>
<!-- Deletes the existing build, docs and dist directory-->
<target name="clean" description="Deletes the existing build, docs and dist directory" >
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="makedir" description="Creates the build, docs and dist directory">
<mkdir dir="${build.dir}" />
<mkdir dir="${dist.dir}" />
</target>
<!-- Creates the build, docs and dist directory-->
<target name="modify" description="modify the source code" >
<spoon classpathref="build.classpath" verbose="true">
<sourceSet dir= "${src.dir}" includes= "*.java" />
<processor type= "com.richardle.Bound2Processor" />
</spoon>
</target>
<!-- Compile Java code -->
<target name="compile" description="Compile Java code" depends="clean, makedir, modify">
<javac destdir="${build.dir}" srcdir="${src.dir}" includeantruntime ="false">
<classpath refid="build.classpath" />
</javac>
</target>
<!--
<target name="jar" description="Make jar file" depends="compile">
<jar destfile="${dist.dir}\com.richardle.testgson.jar">
<manifest>
<attribute name="Main-Class" value="com.richardle.testgson.TestGson"/>
</manifest>
</jar>
</target>
-->
<target name="main" depends="compile">
<description>Main target</description>
</target>
</project>
虽然,我把处理器的编译jar文件和独立勺子jar文件放在classpath中,但是在用Ant编译时仍然会出错
D:\SOFTWARE\Android\TestBound>ant
Buildfile: D:\SOFTWARE\Android\TestBound\build.xml
clean:
[delete] Deleting directory D:\SOFTWARE\Android\TestBound\bin
[delete] Deleting directory D:\SOFTWARE\Android\TestBound\dist
makedir:
[mkdir] Created dir: D:\SOFTWARE\Android\TestBound\bin
[mkdir] Created dir: D:\SOFTWARE\Android\TestBound\dist
modify:
[spoon] Spoon version 2.0
[spoon] error: Unable to add source file : -p does not exist
[spoon] start processing...
[spoon] spoon.support.JavaOutputProcessor
[spoon] end of processing: 1 error
[spoon] java.lang.ClassNotFoundException: com.richardle.Bound2Processor;
[spoon] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[spoon] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[spoon] at java.security.AccessController.doPrivileged(Native Method)
[spoon] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[spoon] at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
[spoon] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[spoon] at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
[spoon] at spoon.AbstractLauncher.run(AbstractLauncher.java:581)
[spoon] at spoon.Launcher.run(Launcher.java:141)
[spoon] at spoon.Launcher.main(Launcher.java:52)
[spoon] Exception in thread "main" java.lang.ClassNotFoundException: com.ric
hardle.Bound2Processor;
[spoon] at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
[spoon] at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
[spoon] at java.security.AccessController.doPrivileged(Native Method)
[spoon] at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
[spoon] at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
[spoon] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
[spoon] at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
[spoon] at spoon.AbstractLauncher.run(AbstractLauncher.java:581)
[spoon] at spoon.Launcher.run(Launcher.java:141)
[spoon] at spoon.Launcher.main(Launcher.java:52)
BUILD FAILED
D:\SOFTWARE\Android\TestBound\build.xml:34: Java returned: 1
Total time: 0 seconds
D:\SOFTWARE\Android\TestBound>
我的工作有问题吗?我必须使用勺子(或一些相关的处理器),我不能使用Java Annotation Processor,因为它无法修改输入源代码,它只是生成新文件。