-->

Ant脚本类路径的多个版本之间进行选择(Ant script to choose between m

2019-06-24 22:00发布

我是新来的Ant脚本。

下面是需求描述

在我的工作区,有各种不同的项目,我必须对我的RAD项目工作和Eclipse IDE的,以及与WebSphere,Tomcat和JBoss的环境..我取得了项目的具体设置,使在RAD项目工作和WebSphere和Eclipse和tomcat的ñJBoss的..

但也有一些文件,如类路径ñ几个配置文件改变了。

这给我留下了工作区的三个版本。

但我的想法是有一个工作空间的类路径的多个版本,例如。 classpath_eclipse,classpath_rad等,并有一个Ant脚本,将正确的文件之间的构建过程中,这取决于IDE选择。

所以,请你们提出一些方法,我怎么能实现这种方法。 全新的蚂蚁。 。:/

Answer 1:

我建议使用Apache的常春藤管理复杂的classpath。 它外化的构建依赖关系到一个单独的ivy.xml文件。

其次,常春藤可以自动下载这样的依赖,源头控制下减少项目的大小。

最后,这种解决方案乍一看可能会出现可怕的复杂。 它的优点是,它与其他构建技术,如兼容的Maven 。

的ivy.xml

常春藤使用“配置”管理罐的逻辑分组。

在这个例子中的代码编译靠在SLF4J API罐,但在运行时使用不同的日志实现:

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

    <configurations>
        <conf name="compile" description="Required to compile application"/>
        <conf name="runtime.simple"  description="Runtime environment with minimal logging" extends="compile"/>
        <conf name="runtime.complex" description="Runtime environment with logback enabled" extends="compile"/>
        <conf name="test"    description="Required for test only" extends="runtime.simple"/>
        <conf name="build"   description="ANT tasks used by build"/>
    </configurations>

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

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

        <!-- complex runtime dependencies -->
        <dependency org="ch.qos.logback" name="logback-classic" rev="1.0.3" conf="runtime.complex->default"/>

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

        <!-- Build dependencies -->
        <dependency org="org.codehaus.groovy" name="groovy-all" rev="1.8.6" conf="build->default"/>
    </dependencies>

</ivy-module>

笔记:

  • 扩展属性使得罐子工会组的创建
  • 默认情况下,常春藤将从下载Maven的中央 (开放存储库现在主持约90%的Java开源软件)。
  • 使用的conf属性,你可以对一个或多个您本地定义配置相关的depedency。
  • 常春藤还可以用来管理第三方ANT任务相关性

build.xml文件

常春藤ANT任务导入为的antlib 。 常春藤cachepath任务用于把一个常春藤管理配置成正常ANT 路径和常春藤报告任务产生依赖性报告。

<project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">

    <target name="init">
        <ivy:resolve/>

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

        <ivy:cachepath pathid="compile.path" conf="compile"/>
        <ivy:cachepath pathid="runtime.simple.path" conf="runtime.simple"/>
        <ivy:cachepath pathid="runtime.complex.path" conf="runtime.complex"/>
        <ivy:cachepath pathid="test.path"    conf="test"/>
        <ivy:cachepath pathid="build.path"   conf="build"/>
    </target>
    ..
    ..

常春藤检索任务用于在应用程序的包装阶段来填充目录:

<target name="war">
    <ivy:retrieve pattern="${build.dir}/libs/[artifact].[ext]" conf="runtime.complex"/>

    <war destfile="myapp.war" webxml="src/metadata/myapp.xml">
        <fileset dir="${src.dir}/html/myapp"/>
        <fileset dir="${src.dir}/jsp/myapp"/>
        <lib dir="${build.dir}/libs"/>
        <classes dir="${build.dir}/classes"/>
    </war>
</target>

IDE配置文件

一个Eclipse插件的常春藤是可用的。

  • http://ant.apache.org/ivy/ivyde/

它也可以生成使用嵌入式IDE配置文件的常规任务。 以下是一个Eclipse例如:

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


Answer 2:

我想和大家分享的是我终于实现的方法。

classpathsettings一些project config xmls这都依赖于运行时。

在每个项目中,我们创建了一个runtime_classpahruntime_settingsconfigxml_runtime每个文件的版本。

创建一个targetant ,在需要runtime为PARAM,itrates过的每一个项目和副本内容classpath_runtimeclasspathsetting_runtime to settings

这overrites目标configxml与内容configxml_runtime



文章来源: Ant script to choose between multiple version of classpaths
标签: eclipse ant rad