Вы можете вызвать главный класс ant с помощью exec:java
goal
pom.xml
<properties>
<target.dir>theTargetDirectory</target.dir>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.apache.tools.ant.launch.Launcher</mainClass>
<arguments>-f,xlatedb.ant.xml</arguments>
<systemProperties>
<systemProperty>
<key>target.dir</key>
<value>${target.dir}</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.10.5</version>
<scope>compile</scope>
</dependency>
</dependencies>
xlatedb.ant.xml
<project default="print-version">
<target name="print-version">
<echo>${ant.version}</echo>
<echo>${target.dir}</echo>
</target>
</project>
mvn compile
Вывод:
--- exec-maven-plugin: 1.6.0: java (по умолчанию) @ stack-55711525-maven-antexec ---
Файл сборки: / xyz / project / xlatedb.ant.xml
версия для печати:
[echo] Apache Ant (TM) версия 1.10.5, скомпилированная 10 июля 2018 года
[echo] theTargetDirectory
BUILD SUCCESSFUL
Общее время: 0секунд
ПРИМЕЧАНИЕ: Если вы хотите, чтобы maven classpath был доступен для ant во время jar
, я думаю, вы можете запустить плагин copy-dependencies
достаточно рано в жизненном циклеи затем укажите выходной каталог зависимостей как classpath для ant.
например,
<path id="class.path">
<fileset dir="target">
<include name="copied-dependencies-dir/*.jar" />
</fileset>
</path>