Включите библиотеки сборки maven-ant в Java-проект Eclipse

Я борюсь с муравьиным телом с затмением.

Я работал, как показано ниже.

  • [GUI] новый проект Java
  • добавлять build.xml в верхней папке проекта
  • запустить файл муравья и УСПЕШНО!
  • пытаюсь закодировать, но как-то автоматическое завершение не работает. (угадав затмение не могу прочитать maven-ant dependency.path)

Итак, я попробовал.

  • добавлять ~/.m2/repository в пути сборки как External class folder - не работает - мне кажется странным включать всю эту папку. Мой текущий проект, мне нужны маленькие библиотеки, но в нем есть целые библиотеки, которые я использую в других проектах.
  • добавить строителей с build.xml Нравится Хотите, чтобы eclipse java проект автоматически запускал файлы сборки ant - не работает ни тот, ни другой.

Как правильно добавить библиотеки maven-ant? Спасибо, что поделились своим опытом и ответили XD

=========== Дополнительная информация ====================

Это мое 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 to 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 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"/>
        </java>
    </target>

    <target name="print-classpath" description="Show the 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 from the 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 up 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 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"/>
        </hibernatetool>
    </target>


    <!-- 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"/>
        </javac>
    </target>

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

Вот так выглядит мой проект.

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

К вашему сведению, я делаю это с книгой [[Harness Hibernate]], написанной Джеймсом Эллиотом из O'reilly.

Еще раз спасибо б

1 ответ

Для того, что вы пытаетесь сделать, вам необходимо указать filesetId и versionId="dependency.versions" в вашем объявлении:

 <artifact:dependencies filesetId="dependency.fileset" versionsId="dependency.versions"

Затем добавьте задачу копирования следующим образом:

 <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>

Параметр to="flatten" сведет ваши зависимости в одну папку, затем вы можете включить эту папку в classpath проекта eclipse или там, где вам это нужно.

Другие вопросы по тегам