DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Related

  • Jakarta NoSQL: Why JPA Is Not Enough for the AI Era
  • Top Java Security Vulnerabilities and How to Prevent Them in Modern Java
  • A Spring Boot App With Half the Startup Time
  • Implementing the Planning Pattern With Java Enterprise and LangChain4j

Trending

  • Solving Data Traffic Jams in Your Network
  • Amazon Quick: AWS's Agentic Workspace, Explained for Engineers
  • One Query, Four GPUs: Tracing a Distributed Training Stall Across Nodes
  • Implementing Observability in Distributed Systems Using OpenTelemetry
  1. DZone
  2. Coding
  3. Java
  4. Apache Ant 1.9.13 and 1.10.5 Released, Supports Java 11 Single-file Source Programs

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.

By 
Jaikiran Pai user avatar
Jaikiran Pai
·
Jul. 21, 18 · News
Likes (1)
Comment
Save
Tweet
Share
15.4K Views

Join the DZone community and get the full member experience.

Join For Free

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.

Java (programming language) Apache Ant

Published at DZone with permission of Jaikiran Pai. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Jakarta NoSQL: Why JPA Is Not Enough for the AI Era
  • Top Java Security Vulnerabilities and How to Prevent Them in Modern Java
  • A Spring Boot App With Half the Startup Time
  • Implementing the Planning Pattern With Java Enterprise and LangChain4j

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook