Hello, here's my two cents:

> Therefore, after opening the projects in Netbeans 12.2, I have added JDK8 in 
> the platform and updated Project Properties accordingly.
Just to confirm, you did this through the project properties window
and not by manually editing project.properties correct?
Speaking of which, what are your current values in that file for
platform.active, javac.source and javac.target?
Do you have any customizations in build.xml, or god forbid build-impl.xml?

> With Netbeans 12.2, when "clean and build" is triggered, ANT picks JDK 15 and 
> compilation fails.
How do you know that ANT picks JDK 15? Do it says so explicitly in the
output or do you assume so because the compilation error consists of a
missing class that is no longer
in the JDK or something like that?
I ask this because even looking at the output in verbose mode I find
it difficult to be sure because in my computer NB runs on JDK 11, and
even when compiling with a JDK 8
the output always start with "Detected Java version: 11 in: ...", but
I know it's compiling with the JDK8 that I set because I did a test
(more on that later).

>Q. How to make ANT pick the JDK mapped to the project in project.properties?
It should work the way you did it, which is going to the project
properties -> Libraries -> Java Platform, and selecting JDK8 from the
dropdown menu (and adding it with the
platform manager button if necessary).
The result should be that the value in project.properties changed from
platform.active=default_platform to platform.active=JDK_8
So verify that first, also check that the path to JDK_8 (or whatever
keyword is set there) actually points to a JDK 8 through the platform
manager window, remember that this path is a user/netbeans wide value
that wouldn't appear in the project.properties file or in any part of
your project (it's in a user properties file outside of netbeans but
you can check that your project uses such file trough
<project>/nbproject/private/private.properties)

In the past I also migrated an Ant web application that needed to run
in JDK 8  from NB8/JDK8 to NB11/JDK 11, and don't remember having this
problem. But maybe that has changed in 12.2, so I tried creating a new
project using File -> New Project, added a simple class and of course
it compiled using JDK 11 (though I had to fix a "Xbootclasspath" error
message), but then I tried switching to JDK8 through the project
properties and to my surprise it no longer compiled but it wasn't a
normal compilation error, something weird like:
"java.lang.RuntimeException: Java result: 1", I couldn't find out what
was the cause but it got fixed after going back to the project
properties and disabling "Compile on Save",
so I recommend that you also try disabling that feature to see if
there is a difference (this feature depends on a plugin called
nb-javac, if the option is grayed out it means that
the plug in is not installed)

Anyway I tested that NB indeed use different JDK by:
* Compiling "import javax.xml.bind.JAXB;" with both JDK8 and JDK11 and
getting the expected results (that class is no longer in the JDK after
9)
* Compiling "var myvar = ""; " with both JDK8 and JDK11 and getting
the expected results (the var keyword doesn't exist in JDK8)
So Netbeans 12.2 works as expected when switching JDK on a fresh ANT
project, Could you check if that's the same case on your computer?
Then we could discard if it's something wrong with your netbeans
installation rather than your project.

If the previous test works, maybe you could try copying your source
files to that new project, without your build.xml personalizations or
anything from the nbproject folder, if that works then maybe you could
try adding the rest of your configurations to figure out the problem
by process of elimination.

Hope it helps.


On Thu, Jan 21, 2021 at 4:02 AM Zahid Rahman <zahidr1...@gmail.com> wrote:
>
> Have a look at this page.
> I think the other way to get ANT to run specified JDK may be to specify in 
> the build.xml
>
> https://stackoverflow.com/questions/949678/ant-is-using-wrong-java-version
>
>
> Z.
>
> https://www.backbutton.co.uk/
> ¯\_(ツ)_/¯
> ♡۶♡۶ ♡۶
>
> On Thu, 21 Jan 2021, 11:53 Zahid Rahman, <zahidr1...@gmail.com> wrote:
>>
>>  > Although, JDK8 appears before JDK15 in the System's PATH variable
>>
>>
>> I don't think you should have two JDKs
>> in the PATH environment variable. It is a but messy.
>>
>> ANT picks JDK 15 and compilation fails. >
>> It looks like ant build script  is  picking up from PATH.
>>
>> if you  run  java - version  get jdk 15 then you are probably picking up jdk 
>> 15 from PATH.
>>
>> Why the project is not picking up JDK
>> from project.properties.
>> Don't know I don't use ANT much.
>>
>>
>> If you are having more than one netbeans IDE on the same machine then 
>> netbeans.conf is provided  so that you can  point to the preferred  jdk for 
>> that IDE.
>>
>>
>>
>> Z.
>>
>> https://www.backbutton.co.uk/
>> ¯\_(ツ)_/¯
>> ♡۶♡۶ ♡۶
>>
>> On Thu, 21 Jan 2021, 11:13 Karan Agrawal, <karan....@gmail.com> wrote:
>>>
>>> Yes Zahid.
>>>
>>> The point is - I would be using Netbeans for Java 11+ projects as well.
>>> Although, JDK8 appears before JDK15 in the System's PATH variable
>>>
>>> If I make a change in netbeans.conf, then I will have to start at least 2 
>>> instances of netbeans and also install nb-javac (probably)
>>>
>>> On Thu, Jan 21, 2021 at 4:24 PM Zahid Rahman <zahidr1...@gmail.com> wrote:
>>>>
>>>> Just a guess.
>>>>
>>>> Do you have JDK 15  installed and included in the windows 10 environment 
>>>> PATH variable  ?
>>>>
>>>>
>>>>
>>>>
>>>> Z.
>>>>
>>>> https://www.backbutton.co.uk/
>>>> ¯\_(ツ)_/¯
>>>> ♡۶♡۶ ♡۶
>>>>
>>>> On Thu, 21 Jan 2021, 10:45 Karan Agrawal, <karan....@gmail.com> wrote:
>>>>>
>>>>> Hello Experts,
>>>>>
>>>>> I have migrated from Netbeans 8.0 to Apache Netbeans 12.2
>>>>>
>>>>> My Java Projects uses JDK 8 with ANT.
>>>>> Therefore, after opening the projects in Netbeans 12.2, I have added JDK8 
>>>>> in the platform and updated Project Properties accordingly.
>>>>>
>>>>> With Netbeans 12.2, when "clean and build" is triggered, ANT picks JDK 15 
>>>>> and compilation fails.
>>>>> Q. How to make ANT pick the JDK mapped to the project in 
>>>>> project.properties?
>>>>>
>>>>> System Details
>>>>>
>>>>> Product Version: Apache NetBeans IDE 12.2
>>>>>
>>>>> Updates: NetBeans IDE is updated to version NetBeans 8.2 Patch 2
>>>>>
>>>>> Java: 15.0.1; Java HotSpot(TM) 64-Bit Server VM 15.0.1+9-18
>>>>>
>>>>> Runtime: Java(TM) SE Runtime Environment 15.0.1+9-18
>>>>>
>>>>> System: Windows 10 version 10.0 running on amd64; Cp1252; en_US (nb)
>>>>>
>>>>> User directory: C:\Users\xxx\AppData\Roaming\NetBeans\12.2
>>>>>
>>>>> Cache directory: C:\Users\xxx\AppData\Local\NetBeans\Cache\12.2
>>>>>
>>>>>
>>>>> ANT_HOME: <PATH>\extide\ant
>>>>>
>>>>> PS: netbeans.conf is one option, but looking for a better alternative.
>>>>>
>>>>> Thanks,
>>>>> Karan



-- 

-Juan Algaba

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org
For additional commands, e-mail: users-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