Java – unable to build NetBeans / ant project
I inherited a project originally written in NetBeans and built it using ant I am an eclipse user and have used ant, but I don't fully understand the specific way NetBeans uses ant I know it uses build impl XML file (imported into build. XML), but I'm confused about how the IDE generates / updates the file
I made some small changes to several classes and wanted to build a jar I tried from build XML and build impl XML runs the "clean" and "jar" targets in eclipse, but gets the following error:
BUILD Failed C:\Devel\Projects\MyProject\nbproject\build-impl.xml:661: The following error occurred while executing this line: C:\Devel\Projects\MyProject\nbproject\build-impl.xml:337: Compile Failed; see the compiler error output for details.
Line 661 is the j2seproject3 element in this target:
<target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-copy-persistence-xml,-compile-depend" if="have.sources" name="-do-compile">
<j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
<copy todir="${build.classes.dir}">
<fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
</copy>
</target>
Line 337 is the javac line for this target:
<target depends="-init-ap-cmdline-properties" name="-init-macrodef-javac-without-processors" unless="ap.supported.internal">
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${src.dir}" name="srcdir"/>
<attribute default="${build.classes.dir}" name="destdir"/>
<attribute default="${javac.classpath}" name="classpath"/>
<attribute default="${javac.processorpath}" name="processorpath"/>
<attribute default="${build.generated.sources.dir}/ap-source-output" name="apgeneratedsrcdir"/>
<attribute default="${includes}" name="includes"/>
<attribute default="${excludes}" name="excludes"/>
<attribute default="${javac.debug}" name="debug"/>
<attribute default="${empty.dir}" name="sourcepath"/>
<attribute default="${empty.dir}" name="gensrcdir"/>
<element name="customize" optional="true"/>
<sequential>
<property location="${build.dir}/empty" name="empty.dir"/>
<mkdir dir="${empty.dir}"/>
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" executable="${platform.javac}" fork="yes" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}" tempdir="${java.io.tmpdir}">
<src>
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
<include name="*"/>
</dirset>
</src>
<classpath>
<path path="@{classpath}"/>
</classpath>
<compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
<compilerarg line="${javac.compilerargs}"/>
<customize/>
</javac>
</sequential>
</macrodef>
</target>
I don't know what these two goals are and why they fail I downloaded netbeans7 and hoped that building it there would succeed, but I would get the same error
Can I safely remove these targets from the build? Do I need to update project Properties file?
Any help that helps to build this is appreciated
Solution
Any other mistakes? What happened after that? Is it a pile of Java compilation errors, or is the < javac > task itself not executed?
< macrodef > is defining a new macro named < javac >, which will execute instead of the original < javac > "Wait a minute!", You said, is there already a < javac > task?
Yes, it looks like it's redefining it I usually think this is a bad thing - especially because it doesn't take the same parameters as < javac > Why not call it < netbeansc > or something?
@Symbols are a bit like attributes They are the parameters you pass to the macro
You have the following points:
<j2seproject3:javac
gensrcdir="${build.generated.sources.dir}"/>
This is called a macro that almost runs original < javac > Compile the task I will ensure that all the properties shown below are defined
<javac
debug="${javac.debug}"
deprecation="${javac.deprecation}"
destdir="${build.classes.dir}"
encoding="${source.encoding}"
excludes="${excludes}"
executable="${platform.javac}"
fork="yes"
includeantruntime="false"
includes="${includes}"
source="${javac.source}"
sourcepath="${empty.dir}"
srcdir="${srcdir}"
target="${javac.target}"
tempdir="${java.io.tmpdir}">
<src>
<dirset dir="${empty.dir}"
erroronmissingdir="false">
<include name="*"/>
</dirset>
</src>
<classpath>
<path path="${javac.classpath"/>
</classpath>
<compilerarg line="${endorsed.classpath.cmd.line.arg}"/>
<compilerarg line="${javac.compilerargs}"/>
<customize/>
