使用Ant在NetBeans中获取动态构建过程中的外部库的最新版本 [英] Use Ant in netbeans to dynamically fetch latest versions of external libraries during build

查看:303
本文介绍了使用Ant在NetBeans中获取动态构建过程中的外部库的最新版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个新手,蚂蚁真的。这是我的问题:我有在NetBeans项目,它使用这是目前美元/ lib目录p $ psent几个外部库。我希望当它试图构建项目我NetBeans中动态获取这些库的最新版本。这是可行的还是我完全错误的道路上?
我对每一个外部库,我在哪里需要指定那些为了这个实验工作的网址吗?
任何帮助是AP preciated,我完全茫然不知如何做到这一点!

I am an Ant newbie really. Here is my problem : I have a project in netbeans which uses several external libraries which are currently present in /lib directory. I want my netbeans to dynamically fetch latest versions of those libraries when it tries to build the project. Is this doable or am I on the completely wrong path? I have URLs for each of the external libraries, where do I need to specify those in order for this experiment to work? Any help on this is appreciated, I am completely clueless about how to do this !

感谢

大家好,
我已经检查了所有的答案和搜索更多关于它们。现在的问题是,虽然看起来行家不可思议的,我的项目已经使用Ant,我不知道如何从蚂蚁迁移到Maven的NetBeans是多么困难。任何帮助吗?
要不然我可以使用Apache常春藤用于这一目的。
为了让你我使用的jar的例子:
阿帕奇公地罐子

所以,你们可以指导我如何去了解呢?这个jar包是一个.zip文件,这样不容易被察觉最新版本我猜里面。

So can you guys guide me how to go about this ? This jar is wrapped inside a .zip file so not easy to detect latest version I guess.

推荐答案

借助 GET 的任务就是做这个使用标准ANT的唯一途径。

The get task is the only way to do this using standard ANT.

与现代的开源开发问题往往一个罐子更依赖于几个,当人们还必须跟踪版本的兼容性,这会变得困难,如果不是不可能的跟踪。

The problem with modern open source development is often one jar depends on several more and when one also must keep track of version compatibilities, this can become difficult if not impossible to keep track of.

的Maven 是一个构建技术,pre-ANT日期,并有3依赖管理功能党的建设依赖。此功能可以在ANT使用复制的的Apache常春藤插件。

Maven is a build technology that pre-dates ANT and has a dependency management feature for 3rd party build dependencies. This functionality can be replicated in ANT by using the Apache ivy plugin.

Java项目来演示使用的常春藤

Java project to demonstrate the use of ivy:

├── build.xml
├── ivy.xml
└── src
    ├── main
    │   ├── java
    │   │   └── org
    │   │       └── demo
    │   │           └── App.java
    │   └── resources
    │       └── log4j.properties
    └── test
        └── java
            └── org
                └── demo
                    └── AppTest.java

有一个额外的的ivy.xml文件,该文件列出了第三方的依赖。这些罐子由来自 Maven的中央储存库,开源Java罐的最大存储库的默认下载。

There is an additional "ivy.xml" file which lists the 3rd party dependencies. These jars will be downloaded by default from the Maven Central repository, the largest repository of open source java jars.

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>

    <configurations>
        <conf name="compile" description="Required to compile application"/>
        <conf name="runtime" description="Additional run-time dependencies" extends="compile"/>
        <conf name="test"    description="Required for test only" extends="runtime"/>
    </configurations>

    <dependencies>
        <!-- compile dependencies -->
        <dependency org="org.slf4j" name="slf4j-api" rev="1.7.5" conf="compile->default"/>

        <!-- runtime dependencies -->
        <dependency org="org.slf4j" name="slf4j-log4j12" rev="1.7.5" conf="runtime->default"/>

        <!-- test dependencies -->
        <dependency org="junit" name="junit" rev="4.11" conf="test->default"/>
    </dependencies>

</ivy-module>

注:


  • 本例使用 SLF4J 日志库,使您可以通过添加不同的罐子可以选择在运行时的实际执行情况

  • 常春藤文件声明3配置,这是依赖的逻辑分组。每个依赖有一个CONF映射告诉常春藤什么罐子将用于

  • 在这个例子中我们code编译针对SLF4J的API罐子,将被配置在运行时使用log4j的。

  • junit的是由ANT需要第三方罐的一个例子。这些也可以通过常春藤下载和管理。

  • This example uses the slf4j logging library which enables you to choose the actual implementation at runtime by adding different jars.
  • The ivy file declares 3 "configurations" which are logical groupings of dependencies. Each dependency has a "conf" mapping that tells ivy what the jar will be used for.
  • In this example our code will compile against the slf4j-api jar and will be configured to use log4j at runtime.
  • junit is an example of a 3rd party jar required by ANT. These can also be downloaded and managed by ivy.
<project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">

    <!--
    ================
    Build properties
    ================
    -->
    <property name="src.dir"          location="src/main/java"/>
    <property name="resources.dir"    location="src/main/resources"/>
    <property name="test.src.dir"     location="src/test/java"/>
    <property name="build.dir"        location="build"/>
    <property name="classes.dir"      location="${build.dir}/classes"/>
    <property name="test.classes.dir" location="${build.dir}/test-classes"/>
    <property name="ivy.reports.dir"  location="${build.dir}/ivy-reports"/>
    <property name="test.reports.dir" location="${build.dir}/test-reports"/>
    <property name="dist.dir"         location="${build.dir}/dist"/>

    <property name="jar.main.class" value="org.demo.App"/>
    <property name="jar.file"       value="${dist.dir}/${ant.project.name}.jar"/>

    <!--
    ===========
    Build setup
    ===========
    -->
    <target name="bootstrap" description="Install ivy">
        <mkdir dir="${user.home}/.ant/lib"/>
        <get dest="${user.home}/.ant/lib/ivy.jar" src="http://search.maven.org/remotecontent?filepath=org/apache/ivy/ivy/2.3.0/ivy-2.3.0.jar"/>
    </target>

    <target name="resolve" description="Use ivy to resolve classpaths">
        <ivy:resolve/>

        <ivy:report todir='${ivy.reports.dir}' graph='false' xml='false'/>

        <ivy:cachepath pathid="compile.path" conf="compile"/>
        <ivy:cachepath pathid="test.path"    conf="test"/>
    </target>

    <!--
    ===============
    Compile targets
    ===============
    -->
    <target name="resources" description="Copy resources into classpath">
        <copy todir="${classes.dir}">
            <fileset dir="${resources.dir}"/>
        </copy>
    </target>

    <target name="compile" depends="resolve,resources" description="Compile code">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false" debug="true" classpathref="compile.path"/>
    </target>

    <target name="compile-tests" depends="compile" description="Compile tests">
        <mkdir dir="${test.classes.dir}"/>
        <javac srcdir="${test.src.dir}" destdir="${test.classes.dir}" includeantruntime="false" debug="true">
            <classpath>
                <path refid="test.path"/>
                <pathelement path="${classes.dir}"/>
            </classpath>
        </javac>
    </target>

    <!--
    ============
    Test targets
    ============
    -->
    <target name="test" depends="compile-tests" description="Run unit tests">
        <mkdir dir="${test.reports.dir}"/>
        <junit printsummary="yes" haltonfailure="yes">
            <classpath>
                <path refid="test.path"/>
                <pathelement path="${classes.dir}"/>
                <pathelement path="${test.classes.dir}"/>
            </classpath>
            <formatter type="xml"/>
            <batchtest fork="yes" todir="${test.reports.dir}">
                <fileset dir="${test.src.dir}">
                    <include name="**/*Test*.java"/>
                    <exclude name="**/AllTests.java"/>
                </fileset>
            </batchtest>
        </junit>
    </target>

    <!--
    =====================
    Build and run targets
    =====================
    -->
    <target name="build" depends="test" description="Create executable jar archive">
        <ivy:retrieve pattern="${dist.dir}/lib/[artifact]-[revision](-[classifier]).[ext]" conf="runtime"/>

        <manifestclasspath property="jar.classpath" jarfile="${jar.file}">
            <classpath>
                <fileset dir="${dist.dir}/lib" includes="*.jar"/>
            </classpath>
        </manifestclasspath>

        <jar destfile="${jar.file}" basedir="${classes.dir}">
            <manifest>
                <attribute name="Main-Class" value="${jar.main.class}" />
                <attribute name="Class-Path" value="${jar.classpath}" />
            </manifest>
        </jar>
    </target>

    <target name="run" depends="build" description="Run code">
        <java jar="${jar.file}" fork="true"/>
    </target>

    <!--
    =============
    Clean targets
    =============
    -->
    <target name="clean" description="Cleanup build files">
        <delete dir="${build.dir}"/>
    </target>

    <target name="clean-all" depends="clean" description="Additionally purge ivy cache">
        <ivy:cleancache/>
    </target>

</project>

请注意的几个项目:


  • 常春藤罐子默认情况下不与蚂蚁运。特殊的引导的目标是用来下载到该ANT使用为它的插件的位置这一点。

  • 的决心目标包含可供下载(和缓存)的依赖,产生这些文件的有用报告和创建可用于编译和测试ANT路径ivy任务。

  • 创建的目标包含常春藤检索任务,其中地方依赖关系到一个分发目录。然后 manifestclasspath 可以利用这些来生成正确的类路径清单条目通过此版本创建的可执行的JAR文件。

  • The ivy jar is not shipped by default with ant. The special "bootstrap" target is used to download this into a location which ANT uses for it's plug-ins.
  • The "resolve" target contains ivy tasks for downloading (and caching) dependencies, generating useful reports on these files and creating ANT paths which can be used for compilation and testing.
  • The "build" target contains the ivy "retrieve" task which places the dependencies into a distribution directory. The manifestclasspath can then use these to generate the correct "Class-path" manifest entry for the executable jar file created by this build.

这篇关于使用Ant在NetBeans中获取动态构建过程中的外部库的最新版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆