Thank you for your suggestions. In the end this is what worked:

In the project Properties->Build->Compiling turn off Compile on Save and in 
Additional Compiler Options add --enable-preview.
On Properties-> Run add --enable-preview. Initially I thought this was not 
required but one of my examples used 'JEP 507: Primitive Types in Patterns, 
instanceof, and switch' that is still in preview. If I was just using 'JEP 512: 
Compact Source Files and Instance Main Methods', no longer in preview, I did 
not need --enable-preview anywhere.

The use of --release 25 did not help but generated a new error about the fact 
that there was already a source and target setting.

Again, thank you to everyone for their advice.

Ken







-----Original Message-----
From: Neil C Smith <neilcsm...@apache.org> 
Sent: June 5, 2025 5:24 AM
To: dev@netbeans.apache.org; Kenneth Fogel <kfo...@dawsoncollege.qc.ca>
Subject: Re: Java 25 and NB

Hi Ken,

On Wed, 4 Jun 2025 at 21:42, Kenneth Fogel <kfo...@dawsoncollege.qc.ca.invalid> 
wrote:
> Error: LinkageError occurred while loading main class JavaSpaghetti
>               java.lang.UnsupportedClassVersionError: JavaSpaghetti 
> (class file version 68.65535) was compiled with preview features that 
> are unsupported. This version of the Java Runtime only recognizes 
> preview features for class file version 69.65535
...
> Ant reports that the java.class.version is 69 which is to be expected using 
> Java 25. Also, if I run a program that does not use any JEP 512: Compact 
> Source Files and Instance Main Methods then it runs fine.
>
> What else might I be missing?

The problem suggests that the code was compiled by NetBeans' Java 24 nbjavac 
and not the JDK's Java 25 javac.  That could be that Compile on Save is 
switched on as Peter suggested - I don't think we changed the default on Ant 
projects, but I'd recommend always switching it off, everywhere.  It might also 
be that you need to add javac.fork=true to the project properties on Ant.

I would question why you're using Ant for this?  The Ant support is probably a 
cause of a number of issues here.  Given the intentions of JEP 512, do you need 
a project here at all?  Creating a new Java file in the Favorites window and 
editing / running that as a single source file seems a better way to explore 
this feature?  You can add VM and program args as file properties.

Best wishes,

Neil

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@netbeans.apache.org
For additional commands, e-mail: dev-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



Reply via email to