how to convert pom.xml to build.xml

2019-09-21 20:29发布

问题:

Am a new bee in this area.

Got a part in pom.xml like below which i need to change in ant buid.xml.

How do i do it? Can i get any help from tutorial or anyone can explain what

<dependency>
    <groupId>com.ask.core</groupId>
    <artifactId>wzlogging</artifactId>
    <version>1.5</version>
    <exclusions>
        <exclusion>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.glassfish.extras</groupId>
            <artifactId>glassfish-embedded-all</artifactId>
        </exclusion>
    </exclusions>
</dependency>

回答1:

In theory it's possible to generate a ANT build file (using XSLT?), but one would need to understand the logic that each plugin implements. In practice only simple Maven builds are feasible candidates.

ANT and Maven are very different build technologies. In ANT you explicitly write all the build logic into the "build.xml" file. Maven on the other hand has most of it's functionality baked in. The "pom.xml" contains no logic instead is used to document meta information about the project (for example the list of dependencies).

Coming from an ANT world this can be very confusing, especially when you want to customise your build. In Maven this is done by declaring plugins, which understand the standard build life-cycle and are able to insert themselves at the correct part of your build.

The purpose of this long-winded explanation is to understand that it's really impossible to know what your plugin is doing by only looking at the POM file.

@Perception recommended ivy. The following answer is related (Convert from ANT to Maven):

  • Converting Ant Web Application Project to Maven Project


回答2:

Maven has a useful Ant plugin to generate a Ant build file from Maven pom.xml easily. Use this maven goal: mvn ant:ant.

In eclipse: Simple generate another run-configuration for a maven build. Name it "Antfile generate". In field "Goals" Enter ant:ant. Apply these changes to you new run configuration. Typ run to start the build. In console log you get an message

[INFO] Wrote Ant project for PROJECTNAME to .



回答3:

Maven and ant are very different tools.

Ant is a build tool primarily, this means it knows how to compile and package source code and run tests, but has no ability to manage project dependencies. Ant uses build.xml files to define where to find the source code and which steps to take to build your project.

Maven is more than just a build tool, it is a project management tool. It allows you to define dependencies in the pom.xml project definition, as well build, test and distribute the application. It also allows sub projects, parent projects and there exist many plugins for many other features. Maven will automatically download the dependencies and manages these dependencies between projects.

Simply put, it is not possible to just convert a Maven POM project into an Ant build.

There are alternatives that allow binary maven dependencies to be utilized within ant builds. Have a look at the Ivy dependency manager for instance.



标签: java maven ant