Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build using ANT preview features of Java 17 in Eclipse

Tags:

java

ant

<target name="compile" depends="init" description="Compile the source.">
    <javac srcdir="${src}" classpathref="classpath" destdir="${build.bin}" compiler="modern" debug="true" debuglevel="lines,vars,source" includeantruntime="false" source="17" target="17" />
</target>

Eclipse won't build cause my switch contains preview code. How can I enable preview and allow compilation using ANT (build.xml)?

error: patterns in switch statements are a preview feature and are disabled by default.

like image 268
Clean code Avatar asked Oct 21 '25 17:10

Clean code


1 Answers

You can use the Ant <compilerarg> element, which can be nested inside the <javac> element.

Specifically, you need the javac --enable-preview argument.

Example:

<target name="compile" depends="init" description="Compile the source.">
    <javac srcdir="${src}" classpathref="classpath" destdir="${build.bin}" compiler="modern" debug="true" debuglevel="lines,vars,source" includeantruntime="false" source="17" target="17">
        <compilerarg value="--enable-preview" />
    </javac>
</target>

More information and examples for compilerarg can be found here: Ant: passing compilerarg into javac

like image 90
andrewJames Avatar answered Oct 23 '25 08:10

andrewJames



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!