Ant script to choose between multiple version of classpaths

前端 未结 2 959
天涯浪人
天涯浪人 2020-12-22 08:02

I am new to Ant scripts.

below is description of requirement

in my workspace, there are various projects and I have to have my project work on RAD and eclips

2条回答
  •  难免孤独
    2020-12-22 08:17

    I'd suggest using Apache ivy for managing complex classpaths. It externalizes your build dependencies into a separate ivy.xml file.

    Secondly, ivy can automatically download such dependencies, reducing the size of your project under source control.

    Finally, this solution at first glance might appear horribly complex. It's advantage is that it's compatible with other build technologies such as Maven.

    Example

    ivy.xml

    Ivy uses "configurations" to manage logical groupings of jars.

    In this example the code compiles against the SLF4J api jars, but at run-time use different logging implementations:

    
        
    
        
            
            
            
            
            
        
    
        
            
            
    
            
            
    
            
            
    
            
            
    
            
            
        
    
    
    

    Notes:

    • The extends attribute enables the creation of jar union sets
    • By default ivy will download from Maven Central (an open repository that now hosts approx 90% of Java open source software).
    • Using the conf attribute you can associated a depedency against one or more of your locally defined configurations.
    • Ivy can also be used to manage 3rd party ANT task dependencies

    build.xml

    The ivy ANT tasks are imported as an antlib. The ivy cachepath task is used to turn an ivy managed configuration into normal ANT paths and the ivy report task produces a dependency report.

    
    
        
            
    
            
    
            
            
            
            
            
        
        ..
        ..
    

    The ivy retrieve task is used to populate a directory during your application's packaging phase:

    
        
    
        
            
            
            
            
        
    
    

    IDE configuration files

    An Eclipse plugin for ivy is available.

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

    It's also possible to generate IDE configuration files using an embedded groovy task. Following is an Eclipse example:

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

提交回复
热议问题