Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Apache Ant 1.9.13 and 1.10.5 Released, Supports Java 11 Single-file Source Programs

DZone's Guide to

Apache Ant 1.9.13 and 1.10.5 Released, Supports Java 11 Single-file Source Programs

Hot off the presses from the JBoss team, take a look at how the latest versions of Apache Ant integrate with Java 11 features.

· Open Source Zone ·
Free Resource

New Report Reveals Open Source Risk Is Still a Mystery to Many. Read more.

We just released 1.9.13 and 1.10.5 versions of Apache Ant. As usual, you can download it from the Ant project download page.

Both these versions are mainly bug fix releases. The 1.10.5 version, however, has a new enhancement to the  java  task. As I blogged previously, Java 11 introduces a new feature where you can execute single-file Java programs without having to explicitly compile them first. Ant 1.10.5 release now supports this feature through a new sourcefile  attribute in the  java  task. More about it can be found the manual of that task.

A simple usage example of this new feature of the  java  task is as follows:

<project default="launch-java" name="Java 11 - launch single-file source program">

 <target name="launch-java"
            description="Simple example of single-file source program execution,
             introduced in Java 11">

        <!-- Make sure Java 11 version is being used -->
        <condition property="java11">
            <javaversion atleast="11"/>
        </condition>    
        <fail unless="java11">Java 11 runtime version is necessary to run this example</fail>        

        <mkdir dir="${basedir}/javasource"/>
        <!-- Write out simple Java code into a file -->
        <echo file="${basedir}/javasource/HelloWorld.java">
            import java.nio.file.Files;
            import java.nio.file.Paths;
            import java.io.BufferedWriter;
            public class HelloWorld {
                public static void main(String[] args) throws Exception {
                    System.out.println("Hello world, " + args[0] + "!");
                }
            }
        </echo>
        <!-- launch the Java source file, using the "sourcefile" attribute -->
        <java sourcefile="${basedir}/javasource/HelloWorld.java" fork="true" failonerror="true" logerror="true">
            <arg value="Java 11"/>
        </java>
    </target>
</project>


As you'll notice, the build file uses the java  task to set the sourcefile attribute to point to a Java source file. The rest of the usage details of the java  task, including passing arguments to the program, continue to remain the same as before.

When you run ant  on this build file, you should see the following output:

 [java] Hello world, Java 11! 

Of course, you will need to use a Java 11 binary to run this against. You can get the early accessible Java 11 binary from here.

Software composition Analysis for DevSecOps. Start finding vulnerabilities in your open source components today.

Topics:
open source ,java ,java release ,java 11 ,apache ant

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}