Reputation: 3781
I am using maven-antrun-plugin to generate classes using Apache Thrift. The plugin works when I specify one thrift file as an argument but fails when I try using a wildcard (*) to generate code for all thrift files. I executed thrift from the command line:
thrift --gen java:beans src/main/resources/*.thrift
And this works.
But when I define this plugin in my 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>
The above fails with error "Could not open input file with realpath".
How do I specify wildcards using maven-antrun-plugin?
Upvotes: 3
Views: 7210
Reputation: 681
@Michael-O When I try to use an asterisk (*) in the arg, Maven complains:
[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
Upvotes: 0
Reputation: 18415
You should rather use the maven thrift plugin. I assume that arg escapes the * and passes as is. Your first command works because the shell does expand the * for you. Thrift ist not able to expand the wildcard itself.
Besides that, the directories use are tremendously wrong.
Edit your file should read:
<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>
Upvotes: 4