There are several options to compile economical files in a maven project:
Option 1: use the maven trift plugin (best)
The Maven Thrift plugin supports creating sources / test sources, recompiling to modifications, etc. Basically, this is the most convenient way to use frugality in a Maven project.
- Put your sources in
src/main/thrift
(or src/test/thrift
for sources of savings). - Set the shore binary bit to / usr / local / bin / thrift (or any other place you prefer)
Add the plugin to the plugins
section of your pom.xml:
<plugin> <groupId>org.apache.thrift.tools</groupId> <artifactId>maven-thrift-plugin</artifactId> <version>0.1.11</version> <configuration> <thriftExecutable>/usr/local/bin/thrift</thriftExecutable> </configuration> <executions> <execution> <id>thrift-sources</id> <phase>generate-sources</phase> <goals> <goal>compile</goal> </goals> </execution> <execution> <id>thrift-test-sources</id> <phase>generate-test-sources</phase> <goals> <goal>testCompile</goal> </goals> </execution> </executions> </plugin>
What it is: the next time you call mvn compile
, java sources will be generated from the savings. The generated sources will be placed in the target/generated-sources/thrift/
directory, and this directory will be added to the compilation path for the java compiler.
Detailed instructions, samples, etc. can be found on Github: https://github.com/dtrott/maven-thrift-plugin .
Option 2: use the Maven Antrun plugin
If for some reason you need to use the antrun plugin, it is better to use the apply
command instead of exec
to process the set of files.
I will write only the basic idea of ββthe ant target, since conditional recompilation during modification probably goes beyond the scope of this question:
<target name="compile-thrift"> <fileset id="thrift.src.files" dir="${src.thrift.dir}"> <include name="**/*.thrift"/> </fileset> <apply executable="${thrift.compiler}" resultproperty="thrift.compile.result" failifexecutionfails="true" failonerror="true" searchpath="true" dir="${src.thrift.dir}"> <arg value="-o"/> <arg value="${thrift.dest.dir}"/> <arg value="--gen"/> <arg value="java"/> <srcfile/> <fileset refid="thrift.src.files"/> </apply> </target>
Option 3: use antrun with exec ant task
If for some reason you need to use the Antrun plugin and the exec
task, then there is a way to do this. I would advise doing this as it is ugly and not portable, but it can work. Use xargs
to call the Thrift compiler for a list of files:
<exec dir="${src.thrift.dir}" executable="bash"> <arg line="ls * | xargs ${thrift.compiler} -o ${thrift.dest.dir} --gen java"/> </exec>
source share