include maven-ant build libs in eclipse java project

I am struggling with maven-ant build with eclipse.

I did work like below steps.

  • [GUI] new java project
  • add build.xml in project top folder
  • run ant file and SUCCEED!
  • trying to code, but somehow auto completion does not work.(guessing eclipse can not read maven-ant dependency.path)

So I tried.

  • add ~/.m2/repository in build path as a External class folder – does not work – It looks weird to me to include whole this folder. My current project, I need little libraries, but it has whole libraries that I uses in other projects.
  • add builders with build.xml like Want an eclipse java project to run ant build files automatically – does not work neither.

How can I add this maven-ant libraries properly? Thanks for sharing your experiences and answers XD

=========== Extra Information ====================

This is my build.xml.

<property name="source.root" value="src"/>
<property name="class.root" value="classes"/>
<property name="data.dir" value="data"/>

<artifact:dependencies pathId="dependency.classpath">
    <dependency groupId="hsqldb" artifactId="hsqldb" version=""/>

    <dependency groupId="org.hibernate" artifactId="hibernate-core" version="4.3.10.Final">
        <exclusion groupId="javax.transaction" artifactId="jta"/>

    <!-- 3.2.4.GA - After hibernate4 need upgrade hibernate-tools -->
    <dependency groupId="org.hibernate" artifactId="hibernate-tools" version="4.3.1.CR1"/>
    <dependency groupId="org.apache.geronimo.specs" artifactId="geronimo-jta_1.1_spec" version="1.1.1"/>

    <!-- java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory -->
    <dependency groupId="commons-logging" artifactId="commons-logging" version="1.2"/>
    <dependency groupId="log4j" artifactId="log4j" version="1.2.17"/>
    <!-- java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder -->
    <dependency groupId="org.slf4j" artifactId="slf4j-log4j12" version="1.7.12"/>   


<path id="project.class.path">
    <pathelement location="${class.root}"/>
    <path refid="dependency.classpath" />

<!-- Explaining how to use hibernate -->
<taskdef name="hibernatetool" 

<target name="db" description="Run HSQLDB database management UI against the database file -- use when application is not running">
    <java classname="org.hsqldb.util.DatabaseManager" fork="yes">
        <classpath refid="project.class.path"/>
        <arg value="-driver"/>
        <arg value="org.hsqldb.jdbcDriver"/>
        <arg value="-url"/>
        <arg value="jdbc:hsqldb:${data.dir}/music/"/>
        <arg value="-user"/>
        <arg value="sa"/>

<target name="print-classpath" description="Show the dependency class path">
    <property name="class.path" refid="dependency.classpath"/>

<!-- Generate java code -->
<target name="codegen" description="Generate Java source from the OR mapping files">
    <hibernatetool destdir="${source.root}">
        <configuration configurationfile="${source.root}/hibernate.cfg.xml"/>

<!-- Creating Sub drectories -->
<target name="prepare" description="Set up build structures">
    <mkdir dir="${class.root}"/>
    <copy todir="${class.root}">
        <fileset dir="${source.root}">
            <include name="**/*.properties"/>
            <include name="**/*.xml"/>

<!-- Creating Schema for mapping files -->
<target name="schema" depends="prepare" description="Generate DB schema from the OR mappinf files">
    <hibernatetool destdir="${source.root}">
        <configuration configurationfile="${source.root}/hibernate.cfg.xml"/>
        <hbm2ddl drop="yes"/>

<!-- Compile Java -->
<!-- added includeantruntime="false" to javac, since terminal compile warning -->
<target name="compile" depends="prepare">
    <javac srcdir="${source.root}" destdir="${class.root}" 
        debug="on" optimize="off" deprecation="on" includeantruntime="false">
        <classpath refid="project.class.path"/>

<target name="ctest" depends="compile">
    <java classname="" fork="true">
        <classpath refid="project.class.path"/>

and This is what my project looks like.

-- source codes (includes hibernate.cfg.xml)
-- compiled classes
-- logs and queries

FYI, I am doing this with a book named [[Harness Hibernate]] written by James Elliot from O’reilly.

Thanks again b

Source: eclipse

Leave a Reply