使用Apache Ivy和netbeans

时间:2012-07-23 12:29:17

标签: java netbeans ant ivy

我有一个使用netbeans开发的现有项目,我想将Apache Ivy集成到项目中。我更新了netbeans生成的build.xml来下载ivy(如果需要)并使用它来检索依赖项。

有没有人知道如何将下载的依赖项添加到项目的构建路径中,这样它就可以正常编译,并且不会在界面中显示缺少的库错误。

如果可行的话,我更愿意在不使用netbeans插件的情况下这样做。如果没有,你会建议使用什么插件。

编辑:我现在也在“-pre-init”目标中执行此操作,如果它具有任何相关性。

3 个答案:

答案 0 :(得分:1)

不幸的是我不熟悉netbeans的配置文件。

以下是我用于生成Eclipse元数据文件的集成目标:

  • 的.classpath
  • 的.project

也许你可以适应它。

<target name="eclipse">
    <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>

    <ivy:cachefileset setid="libfiles" conf="compile"/>

    <groovy>
    <arg value="${src.dir}"/>
    <arg value="${build.dir}/classes"/>

    import groovy.xml.MarkupBuilder

    //
    // Generate the project file
    //
    project.log("Creating .project")

    new File(".project").withWriter { writer ->
        def xml = new MarkupBuilder(writer)

        xml.projectDescription() {
            name(project.name)
            comment()
            projects()
            buildSpec() {
                buildCommand() {
                    name("org.eclipse.jdt.core.javabuilder")
                    arguments()
                }
            }
            natures() {
                nature("org.eclipse.jdt.core.javanature")
            }
        }
    }

    //
    // Generate the classpath file
    //
    // The "lib" classpathentry fields are populated using the ivy artifact report
    //
    project.log("Creating .classpath")

    new File(".classpath").withWriter { writer ->
        def xml = new MarkupBuilder(writer)

        xml.classpath() {
            classpathentry(kind:"src",    path:args[0])
            classpathentry(kind:"output", path:args[1])
            classpathentry(kind:"con",    path:"org.eclipse.jdt.launching.JRE_CONTAINER")

            project.references.libfiles.each {
                classpathentry(kind:"lib", path:it)
            }
        }
    }
    </groovy>        
</target>

答案 1 :(得分:0)

也许你可以试试http://code.google.com/p/ivybeans/

答案 2 :(得分:0)

如果您不想使用ivybeans插件,也许您可​​以激发自己对插件生成的不同ant任务:

https://code.google.com/p/ivybeans/source/browse/trunk/ivybeans/ivy-module/src/com/googlecode/ivybeans/module/resources/ivy-impl_.xml