gpt4 book ai didi

java - 如何在 ant maven 任务中使用外部库/依赖项?

转载 作者:行者123 更新时间:2023-11-30 03:39:49 25 4
gpt4 key购买 nike

我目前有一个 Maven 构建,它调用 ant 任务来运行。此 ant 任务依赖于一些外部库。这些库目前在我的系统中进行了硬编码。我想将这些外部库移至本地 Maven 存储库,并让 Maven 从存储库中检索它们,但我不确定如何执行此操作。

我当前的任务定义为(为了简洁编辑了完整的任务定义):

        <plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>

<!-- Ant Custom Folder copying plugin -->
<execution>
<id>rename_files</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antlib.xml" classpath="${env.ANT_HOME}/lib/ant-contrib-1.0b3.jar" />
<taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" classpath="${env.ANT_HOME}/lib/AntelopeTasks_3.4.1.jar" />
<typedef name="trim" classname="ise.antelope.tasks.typedefs.string.Trim" classpath="${env.ANT_HOME}/lib/AntelopeTasks_3.4.1.jar" />
<typedef name="lastindexof" classname="ise.antelope.tasks.typedefs.string.LastIndexOf" classpath="${env.ANT_HOME}/lib/AntelopeTasks_3.4.1.jar" />
<typedef name="substring" classname="ise.antelope.tasks.typedefs.string.Substring" classpath="${env.ANT_HOME}/lib/AntelopeTasks_3.4.1.jar" />
<typedef name="listfiles" classname="ise.antelope.tasks.typedefs.file.FileList" classpath="${env.ANT_HOME}/lib/AntelopeTasks_3.4.1.jar" />
<taskdef name="fileutil" classname="ise.antelope.tasks.FileUtilTask" classpath="${env.ANT_HOME}/lib/AntelopeTasks_3.4.1.jar" />

<!-- CSS -->
<for param="file">
<path>
<fileset dir="target\Com-${project.version}\style\" includes="*.css" />
</path>
<sequential>
<fileutil file="@{file}" property="fileWithoutPath">
<listfiles includepath="false" />
</fileutil>
</sequential>
</for>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

我知道我可以定义<dependencies>作为我的插件定义的一部分,但不确定如何重新定义我的 taskdef指向依赖项与 rar jar 文件。

最佳答案

经过多次筛选后,我发现我可以执行以下操作。

        <plugin>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
</dependency>
<dependency>
<groupId>org.tigris.antelope</groupId>
<artifactId>antelopetasks</artifactId>
<version>3.4.1</version>
</dependency>
</dependencies>
<executions>

<!-- Ant Custom Folder copying plugin -->
<execution>
<id>rename_files</id>
<phase>process-resources</phase>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="maven.plugin.classpath" />
<taskdef name="stringutil" classname="ise.antelope.tasks.StringUtilTask" classpathref="maven.plugin.classpath" />
<typedef name="trim" classname="ise.antelope.tasks.typedefs.string.Trim" classpathref="maven.plugin.classpath" />
<typedef name="lastindexof" classname="ise.antelope.tasks.typedefs.string.LastIndexOf" classpathref="maven.plugin.classpath" />
<typedef name="substring" classname="ise.antelope.tasks.typedefs.string.Substring" classpathref="maven.plugin.classpath" />
<typedef name="listfiles" classname="ise.antelope.tasks.typedefs.file.FileList" classpathref="maven.plugin.classpath" />
<taskdef name="fileutil" classname="ise.antelope.tasks.FileUtilTask" classpathref="maven.plugin.classpath" />

</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

只需使用 classpathref 并指向任务定义中的 maven.plugin.classpath 即可。

希望这对将来的其他人有帮助。

关于java - 如何在 ant maven 任务中使用外部库/依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27045415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com