我使用maven-antrun-plugin来生成使用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>
上面的错误提示"Could not open input file with realpath".
如何使用maven- anrun -plugin指定通配符?
您应该使用maven thrift插件。我假设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>
@Michael-O当我尝试在参数中使用星号(*)时,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