gpt4 book ai didi

java - Maven antrun 插件。将目录中的所有文件作为参数传递

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:25:15 24 4
gpt4 key购买 nike

我正在使用 maven-antrun-plugin 生成使用 Apache Thrift 的类。当我将一个 thrift 文件指定为参数时该插件工作,但当我尝试使用通配符 (*) 为所有 thrift 文件生成代码时失败。我从命令行执行节俭:

thrift --gen java:beans src/main/resources/*.thrift

这行得通。

但是当我在我的 pom.xml 中定义这个插件时

            <plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="target/generated-sources" />
<exec executable="${thrift.executable}" failonerror="true">
<arg value="--gen" />
<arg value="java:beans" />
<arg value="-o" />
<arg value="target/generated-sources" />
<arg value="${basedir}/src/main/resources/*.thrift" />
</exec>
<copy todir="src/main/java" overwrite="true">
<fileset dir="target/generated-sources/gen-javabean" />
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

上述失败并出现错误“无法使用真实路径打开输入文件”。

如何使用 maven-antrun-plugin 指定通配符?

最佳答案

您应该使用 maven thrift plugin .我假设 arg 转义 * 并按原样传递。您的第一个命令有效,因为 shell 确实为您扩展了 *。 Thrift 无法扩展通配符本身。

除此之外,目录的使用也大错特错。

编辑你的文件应该是:

<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<!-- always use properties if available -->
<mkdir dir="${build.directory}/generated-sources" />
<exec executable="${thrift.executable}" failonerror="true">
<arg value="--gen" />
<arg value="java:beans" />
<arg value="-o" />
<arg value="${build.directory}/generated-sources/thrift" />
<!-- since this is a special type of source, it has to be in its own dir -->
<arg value="src/main/thrift/*.thrift" />
</exec>
<!-- You never ever copy generated stuff back into src/* -->
<!-- use Build Helper Maven Plugin to add the generated source -->
<copy todir="src/main/java" overwrite="true">
<fileset dir="target/generated-sources/gen-javabean" />
</copy>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

关于java - Maven antrun 插件。将目录中的所有文件作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6781037/

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