2
我的build.xml文件看起來像以下:如何使用ant爲antlr3生成的類添加包聲明?
<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>
它產生BoolExprLexer.java和BoolExprParser.java文件夾/ src目錄/ COM /包/ ANTLR,這就是我想要的,但生成的文件屬於默認包。我怎樣才能讓com成爲com.package.antlr的一部分?
太棒了!非常感謝! –