include maven-ant build libs in eclipse java project -
i struggling maven-ant build eclipse.
i did work below steps.
- [gui] new java project
- add
build.xml
in project top folder - run ant file , succeed!
- trying code, somehow auto completion not work.(guessing eclipse can not read maven-ant
dependency.path
)
so tried.
- add
~/.m2/repository
in build pathexternal class folder
- not work - looks weird me include whole folder. current project, need little libraries, has whole libraries uses in other projects. - add builders
build.xml
want eclipse java project run ant build files automatically - not work neither.
how can add maven-ant libraries properly? sharing experiences , answers xd
=========== information ====================
this build.xml
.
<?xml version="1.0" encoding="utf-8"?> <project name="hibernateex2" default="db" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant"> <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="1.8.0.10"/> <dependency groupid="org.hibernate" artifactid="hibernate-core" version="4.3.10.final"> <exclusion groupid="javax.transaction" artifactid="jta"/> </dependency> <!-- 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"/> </artifact:dependencies> <path id="project.class.path"> <pathelement location="${class.root}"/> <path refid="dependency.classpath" /> </path> <!-- explaining how use hibernate --> <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.hibernatetooltask" classpathref="project.class.path"/> <target name="db" description="run hsqldb database management ui against database file -- use when application 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"/> </java> </target> <target name="print-classpath" description="show dependency class path"> <property name="class.path" refid="dependency.classpath"/> <echo>${class.path}</echo> </target> <!-- generate java code --> <target name="codegen" description="generate java source or mapping files"> <hibernatetool destdir="${source.root}"> <configuration configurationfile="${source.root}/hibernate.cfg.xml"/> <hbm2java/> </hibernatetool> </target> <!-- creating sub drectories --> <target name="prepare" description="set build structures"> <mkdir dir="${class.root}"/> <copy todir="${class.root}"> <fileset dir="${source.root}"> <include name="**/*.properties"/> <include name="**/*.xml"/> </fileset> </copy> </target> <!-- creating schema mapping files --> <target name="schema" depends="prepare" description="generate db schema or mappinf files"> <hibernatetool destdir="${source.root}"> <configuration configurationfile="${source.root}/hibernate.cfg.xml"/> <hbm2ddl drop="yes"/> </hibernatetool> </target> <!-- compile java --> <!-- added includeantruntime="false" 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"/> </javac> </target> <target name="ctest" depends="compile"> <java classname="org.owls.ht.createtest" fork="true"> <classpath refid="project.class.path"/> </java> </target> </project>
and project looks like.
src -- source codes (includes hibernate.cfg.xml) classes -- compiled classes data -- logs , queries build.xml
fyi, doing book named [[harness hibernate]] written james elliot o'reilly.
thanks again b
for trying do, need filesetid , versionsid="dependency.versions" in declaration of:
<artifact:dependencies filesetid="dependency.fileset" versionsid="dependency.versions"
then add copy task so:
<copy todir="${lib.dir}"> <fileset refid="dependency.fileset" /> <mapper classpathref="maven-ant-tasks.classpath" classname="org.apache.maven.artifact.ant.versionmapper" from="${dependency.versions}" to="flatten" /> </copy>
the to="flatten" flaten dependencies single folder, can include folder on classpath of eclipse project or wherever need it.
Comments
Post a Comment