Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The are several options to compile thrift files in maven project:</p> <h2>Option 1: Use maven thrift plugin (the best one)</h2> <p>Maven Thrift plugin supports generation of sources/test sources, recompile on modify, etc. Basically, it's the most convenient way to use thrift in Maven project.</p> <ol> <li>Put your sources in <code>src/main/thrift</code> (or <code>src/test/thrift</code> for test thrift sources).</li> <li>Install the thrift binary to /usr/local/bin/thrift (or any other place, you prefer)</li> <li><p>Add the plugin to the <code>plugins</code> section of your pom.xml:</p> <pre><code> &lt;plugin&gt; &lt;groupId&gt;org.apache.thrift.tools&lt;/groupId&gt; &lt;artifactId&gt;maven-thrift-plugin&lt;/artifactId&gt; &lt;version&gt;0.1.11&lt;/version&gt; &lt;configuration&gt; &lt;thriftExecutable&gt;/usr/local/bin/thrift&lt;/thriftExecutable&gt; &lt;/configuration&gt; &lt;executions&gt; &lt;execution&gt; &lt;id&gt;thrift-sources&lt;/id&gt; &lt;phase&gt;generate-sources&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;compile&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;execution&gt; &lt;id&gt;thrift-test-sources&lt;/id&gt; &lt;phase&gt;generate-test-sources&lt;/phase&gt; &lt;goals&gt; &lt;goal&gt;testCompile&lt;/goal&gt; &lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; </code></pre></li> </ol> <p>That's it: next time you call <code>mvn compile</code> java sources will be generated from thrift. Generated sources will be placed into <code>target/generated-sources/thrift/</code> directory, and this directory will be added to the compile path for java compiler.</p> <p>You can find the detailed instructions, samples and more on the Github: <a href="https://github.com/dtrott/maven-thrift-plugin" rel="nofollow">https://github.com/dtrott/maven-thrift-plugin</a>.</p> <h2>Option 2: Use Maven Antrun plugin</h2> <p>If it's necessary for some reason to use antrun plugin, it's better to use <code>apply</code> command instead of <code>exec</code> to process a set of files.</p> <p>I'll write only a basic idea of ant target, since conditional recompilation on modification is probably out of scope of this question:</p> <pre><code>&lt;target name="compile-thrift"&gt; &lt;!-- Define fileset of thrift files --&gt; &lt;fileset id="thrift.src.files" dir="${src.thrift.dir}"&gt; &lt;include name="**/*.thrift"/&gt; &lt;/fileset&gt; &lt;!-- Invoke thrift binary for each of these files --&gt; &lt;apply executable="${thrift.compiler}" resultproperty="thrift.compile.result" failifexecutionfails="true" failonerror="true" searchpath="true" dir="${src.thrift.dir}"&gt; &lt;arg value="-o"/&gt; &lt;arg value="${thrift.dest.dir}"/&gt; &lt;arg value="--gen"/&gt; &lt;arg value="java"/&gt; &lt;srcfile/&gt; &lt;fileset refid="thrift.src.files"/&gt; &lt;/apply&gt; &lt;/target&gt; </code></pre> <h2>Option 3: Use antrun with exec ant task</h2> <p>If it's absolutely necessary for some reason to use Antrun plugin and <code>exec</code> task, there's a way to do so. I'd advise against it, since it's ugly and not portable, but it might work. Use <code>xargs</code> to invoke Thrift compiler for a list of files:</p> <pre><code>&lt;exec dir="${src.thrift.dir}" executable="bash"&gt; &lt;arg line="ls * | xargs ${thrift.compiler} -o ${thrift.dest.dir} --gen java"/&gt; &lt;/exec&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload