Java 使用antcontrib<;如果>;通过maven antrun插件执行任务
我的maven java项目使用maven antrun插件来执行部署我的应用程序的deploy.xml ant脚本。deploy.xml使用了Java 使用antcontrib<;如果>;通过maven antrun插件执行任务,java,maven,ant-contrib,maven-antrun-plugin,Java,Maven,Ant Contrib,Maven Antrun Plugin,我的maven java项目使用maven antrun插件来执行部署我的应用程序的deploy.xml ant脚本。deploy.xml使用了任务,这似乎是导致问题的原因 [信息]执行任务 [taskdef]无法从资源网/sf/antcontrib/antlib.xml加载定义。找不到 部署: [信息]---------------------------------------------------------------- [错误]生成错误 [信息]-------------------
任务,这似乎是导致问题的原因
[信息]执行任务[taskdef]无法从资源网/sf/antcontrib/antlib.xml加载定义。找不到 部署:
[信息]----------------------------------------------------------------
[错误]生成错误
[信息]----------------------------------------------------------------
[INFO]发生Ant BuildException:执行此行时发生以下错误:
E:\My\u Workspace\xxxxxx\xxxxxx\xxxxxxx\xxxxxxx\deploy.xml:24:问题:无法创建任务或类型if
原因:名称未定义。
操作:检查拼写。
操作:检查是否已声明任何自定义任务/类型。
措施:检查是否发生了任何/声明 这是我的pom中的antrun插件配置
<plugin>
<inherited>false</inherited>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>remote-deploy</id>
<phase>install</phase>
<configuration>
<tasks>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="maven.plugin.classpath"/>
<property name="compile_classpath" refid="maven.compile.classpath" />
<property name="runtime_classpath" refid="maven.runtime.classpath" />
<property name="plugin_classpath" refid="maven.plugin.classpath" />
<echo message="compile classpath: ${compile_classpath}"/>
<echo message="runtime classpath: ${runtime_classpath}"/>
<echo message="plugin classpath: ${plugin_classpath}"/>
<ant antfile="${basedir}/deploy.xml">
<target name="deploy" />
</ant>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>1.0b3</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-jsch</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
</plugin>
假的
org.apache.maven.plugins
maven antrun插件
远程部署
安装
跑
抗辩人
抗辩人
1.0b3
org.apache.ant
蚂蚁
1.7.1
org.apache.ant
ant jsch
1.7.1
。。这里是my deploy.xml中的相关部分
<target name="deploy" if="deploy">
<if> <!-- line 24 -->
<and>
为什么我看我的maven回购我可以看到ant contrib/ant contrib/1.0b3/ant-contrib-1.0b3.jar
当我看jar内部时,我可以看到net/sf/antcontrib/antcontrib.properties
,所以没有问题
当我检查maven.compile.classpath
、maven.compile.classpath
和maven.compile.classpath
的值时,我看不到对antcontrib
的任何引用,这是问题吗?当antcontrib
被定义为依赖项时,它们为什么不出现?好的,我已经解决了
将依赖项移出
标记,并将它们与其他项目依赖项放在一起,似乎已经做到了这一点。我认为添加ant来编译类路径以运行maven插件不是一个很好的主意
我使用Maven 3.0.4,它通过为ant contrib标记指定名称空间来工作,例如:
<configuration>
<target>
<echo message="The first five letters of the alphabet are:"/>
<ac:for list="a,b,c,d,e" param="letter" xmlns:ac="antlib:net.sf.antcontrib">
<sequential>
<echo>Letter @{letter}</echo>
</sequential>
</ac:for>
</target>
</configuration>
另一个解决方案是:将ant-contrib-1.0b3.jar保留为一个路径,然后像这样定义它
<property name="runningLocation" location="" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="${runningLocation}/ant-contrib-1.0b3.jar" />
</classpath>
</taskdef>
然后
我将完整的代码示例放在这里,您可以下载它我发现您需要在插件中包含ant contrib依赖项,这将使taskdef标记能够找到antcontrib.properties
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>20020829</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>copy-and-rename-template-files</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name = "copy-and-rename-template-files">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<if>
<available file="src/main/resources/docker/templates" type="dir"/>
<then>
<copy todir="${project.build.directory}/docker">
<fileset dir="src/main/resources/docker/templates">
<include name="**/*"/>
</fileset>
</copy>
<move todir="${project.build.directory}/docker">
<fileset dir="${project.build.directory}/docker">
<include name="*"/>
</fileset>
<mapper>
<regexpmapper from="(.*)project(.*)" to="\1${project.artifactId}\2"/>
</mapper>
</move>
</then>
<else>
<echo>src/main/resources/docker/templates does not exist, skipping processing docker templates</echo>
</else>
</if>
</target>
</configuration>
</execution>
</executions>
</plugin>
org.apache.maven.plugins
maven antrun插件
抗辩人
抗辩人
20020829
复制和重命名模板文件
准备包装
跑
src/main/resources/docker/templates不存在,正在跳过处理docker模板
正如另一个答案所解释的,在编译类路径中包含ant依赖项以运行Maven插件不是一个好主意。奇怪的是,我必须这样做才能下载它。然后,将其移回插件依赖项。我只是希望这是一个IDE问题。
<target name="doSomething">
<if>
<equals arg1="${someProp}" arg2="YES" />
<then>
<echo message="It is YES" />
</then>
<else>
<echo message="It is not YES" />
</else>
</if>
</target>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<dependencies>
<dependency>
<groupId>ant-contrib</groupId>
<artifactId>ant-contrib</artifactId>
<version>20020829</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>copy-and-rename-template-files</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name = "copy-and-rename-template-files">
<taskdef resource="net/sf/antcontrib/antcontrib.properties"/>
<if>
<available file="src/main/resources/docker/templates" type="dir"/>
<then>
<copy todir="${project.build.directory}/docker">
<fileset dir="src/main/resources/docker/templates">
<include name="**/*"/>
</fileset>
</copy>
<move todir="${project.build.directory}/docker">
<fileset dir="${project.build.directory}/docker">
<include name="*"/>
</fileset>
<mapper>
<regexpmapper from="(.*)project(.*)" to="\1${project.artifactId}\2"/>
</mapper>
</move>
</then>
<else>
<echo>src/main/resources/docker/templates does not exist, skipping processing docker templates</echo>
</else>
</if>
</target>
</configuration>
</execution>
</executions>
</plugin>