我的 build.xml 如下所示:
<property name="lib" value="${basedir}/lib" />
<property name="src" value="${basedir}/src" />
<property name="package" value="com/package/antlr" />
<path id="compile.classpath">
<fileset dir="${lib}">
<include name="antlr-3.5-complete.jar" />
</fileset>
</path>
<!-- Check if ANTLR3 can be found in the classpath -->
<target name="antlr_classpath">
<whichresource property="antlr.in.classpath" class="org.antlr.Tool">
<classpath>
<path refid="compile.classpath" />
</classpath>
</whichresource>
<fail message="ANTLR3 not found in CLASSPATH">
<condition>
<not>
<isset property="antlr.in.classpath" />
</not>
</condition>
</fail>
<echo>ANTLR3 found via CLASSPATH</echo>
</target>
<!-- Antlr3 is called here -->
<target name="antlr" depends="antlr_classpath">
<java classname="org.antlr.Tool" fork="true" failonerror="true">
<classpath>
<path refid="compile.classpath" />
</classpath>
<arg value="-verbose" />
<arg value="-make"/>
<arg value="-o" />
<arg path="${src}/${package}" />
<arg path="${src}/${package}/BoolExpr.g" />
</java>
</target>
它在文件夹/src/com/package/antlr 中生成 BoolExprLexer.java 和 BoolExprParser.java,这是我想要的,但生成的文件属于默认包。我怎样才能让他们成为 com.package.antlr 的一部分?