I have an Ant build.xml file that works fine on the command line: it compiles, creates a JAR, and I can just execute the main method from the JAR. The build.xml file refers to several third-party libraries that are scattered here and there. When creating a JAR, the script does not include all third-party libraries in the JAR. Instead, it puts its way into the JAR manifest. This helps keep my JAR slim and neat.
I would like to be able to edit and debug my project in Eclipse, but I cannot find an easy way to do this. Can I use the Ant project to create a project and it seems to work. However, Eclipse has difficulty finding third-party rights, and therefore, Eclipse has two problems:
- it shows (in a text editor) many compilation errors, because the many classes are undefined and
- he cannot perform a jar.
I can solve both of these problems by manually specifying in two difference places (i.e. the build path through Properties->Java Build Path->Libraries and the execution class path through Run Configurations->Classpath ), all third-party libraries. But it seems to me that I do not need to do this manually, since all third-party libraries are already listed in the JAR manifest. What am I doing wrong?
Here is my build.xml file:
<property name="src" location="./src" /> <property name="build" location="./build"/> <property name="dist" location="./dist"/> <property name="logs" location="./logs"/> <property name="docs" location="./docs"/> <property name="jar" location="${dist}/dynamic_analyzer.jar"/> <property name="lib" location="../../thirdparty/lib"/> <property name="hive-util" location="../../hive-utils/dist"/> <property name="hpdb" location="../../hive-db/hpdb/dist"/> <property name="static" location="../../hive-backend/static_analyzer/dist"/> <property name="mainclass" value="com.datawarellc.main.DynamicMain"/> <path id="dep.runtime"> <fileset dir="${lib}" includes="**/*.jar"/> <fileset dir="${hive-util}" includes="**/*.jar"/> <fileset dir="${hpdb}" includes="**/*.jar"/> <fileset dir="${static}" includes="**/*.jar"/> </path> <target name="clean"> <delete dir="${build}"/> <delete dir="${dist}"/> <delete dir="${docs}"/> <delete dir="${logs}"/> </target> <target name="init"> <tstamp/> <mkdir dir="${build}"/> <mkdir dir="${dist}"/> <mkdir dir="${logs}"/> </target> <target name="compile" depends="init"> <javac srcdir="${src}" destdir="${build}" debug="on" includeantruntime="false"> <classpath refid="dep.runtime" /> </javac> <property name="myclasspath" refid="dep.runtime"/> <echo message="Classpath = ${myclasspath}"/> </target> <target name="jar" depends="compile"> <manifestclasspath property="manifest_cp" jarfile="${jar}" maxParentLevels="10"> <classpath refid="dep.runtime" /> </manifestclasspath> <jar jarfile="${jar}" basedir="${build}"> <manifest> <attribute name="Main-Class" value="${mainclass}"/> <attribute name="Class-Path" value="${manifest_cp}"/> </manifest> <zipfileset dir="${src}" includes="**/*.xml" /> </jar> </target>
You can see that I have third-party libraries in several directories ( ${lib} , ${hive-util} , ${hpdb} and ${static} ). I use them to create a path called dep.runtime . Then I include dep.runtime in the manifest when creating my jar. How can I force Eclipse to use the same dep.runtime for the build path and class path at runtime?
source share