Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You <em>can</em> call ant scripts from Java code. </p> <p>See <a href="http://ant.apache.org/manual/running.html" rel="noreferrer">this article</a> (scroll down to the "Running Ant via Java" section) and <a href="http://www.ibm.com/developerworks/websphere/library/techarticles/0502_gawor/0502_gawor.html#sec2b" rel="noreferrer">this article</a>:</p> <pre><code> File buildFile = new File("build.xml"); Project p = new Project(); p.setUserProperty("ant.file", buildFile.getAbsolutePath()); p.init(); ProjectHelper helper = ProjectHelper.getProjectHelper(); p.addReference("ant.projectHelper", helper); helper.parse(p, buildFile); p.executeTarget(p.getDefaultTarget()); </code></pre> <p><strong>Update</strong></p> <p>I tried with the following ant file , it did not "tell" anything (no console output), but it <strong>worked</strong>: the file was indeed moved</p> <pre><code> &lt;project name="testproject" default="test" basedir="."&gt; &lt;target name="test"&gt; &lt;move file="test.txt" tofile="test2.txt" /&gt; &lt;/target&gt; &lt;/project&gt; </code></pre> <p>And when I try it again (when there is no <code>test.txt</code> to move(it is already moved)), I got an <code>java.io.FileNotFoundException</code>.</p> <p>I think this is what you would expect when you run something from Java.</p> <p>If you want the console output of the ant tasks, you might want to add a Logger as a build listener. </p> <p>From @Perception's answer below.</p> <pre><code> DefaultLogger consoleLogger = new DefaultLogger(); consoleLogger.setErrorPrintStream(System.err); consoleLogger.setOutputPrintStream(System.out); consoleLogger.setMessageOutputLevel(Project.MSG_INFO); p.addBuildListener(consoleLogger); </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