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

Java Maven antrun插件。将目录中的所有文件作为参数传递,java,ant,maven,Java,Ant,Maven,我正在使用maven antrun插件使用Apache Thrift生成类。当我指定一个thrift文件作为参数时,该插件工作,但当我尝试使用通配符(*)为所有thrift文件生成代码时,插件失败。我从命令行执行了thrift: thrift --gen java:beans src/main/resources/*.thrift 这是有效的 但是当我在pom.xml中定义这个插件时 <plugin> <artifactId&g

我正在使用maven antrun插件使用Apache Thrift生成类。当我指定一个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插件
生成源
生成源
跑
上述操作失败,错误为“无法使用realpath打开输入文件”

如何使用maven antrun插件指定通配符?

您应该使用。 我假设arg逃脱了*并按原样通过。您的第一个命令之所以有效,是因为shell确实为您展开了*。节俭不能扩展通配符本身

除此之外,使用的目录是非常错误的

编辑您的文件应为:

<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>

maven antrun插件
生成源
生成源
跑

@Michael-O当我试图在arg中使用星号(*)时,Maven抱怨:

[INFO] --- maven-antrun-plugin:1.3:run (generate-sources) @ ---
[INFO] Executing tasks
     [exec] 
     [exec] [FAILURE:arguments:1] Could not open input file with realpath:
src/main/thrift/*.thrift
     [exec] Result: 1

我不明白你所说的“目录使用大错特错”是什么意思