This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 236364 - Compiling With Maven For Java 8
Summary: Compiling With Maven For Java 8
Status: RESOLVED WORKSFORME
Alias: None
Product: projects
Classification: Unclassified
Component: Maven (show other bugs)
Version: 7.4
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Assignee: Milos Kleint
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-25 11:37 UTC by abien
Modified: 2014-05-15 20:24 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
IDE log (273.02 KB, text/plain)
2013-09-25 11:37 UTC, abien
Details

Note You need to log in before you can comment on or make changes to this bug.
Description abien 2013-09-25 11:37:55 UTC
Product Version = NetBeans IDE 7.4 RC1 (Build 201309162201)
Operating System = Mac OS X version 10.8.5 running on x86_64
Java; VM; Vendor = 1.7.0
Runtime = Java HotSpot(TM) 64-Bit Server VM 23.25-b01

Although Java 8 is selected, if NetBeans runs on JDK 1.7, you will get the following error attempting compiling Java 8 / javafx applications:

-------------------------------------------------------------
COMPILATION ERROR : 
-------------------------------------------------------------
Failure executing javac, but could not parse the error:
javac: invalid target release: 1.8
Usage: javac <options> <source files>
use -help for a list of possible options


Also NetBeans reports errors in the editor and cannot find JavaFX classes. 

Reproducer: try to build the project https://github.com/AdamBien/lightfish/tree/master/multilight/lightview with NetBeans on OSX running on JDK 1.7.
Comment 1 abien 2013-09-25 11:37:57 UTC
Created attachment 140452 [details]
IDE log
Comment 2 Marian Mirilovic 2013-09-25 12:56:26 UTC
What do you mean by "Although Java 8 is selected..." ?

Go to Project | Properties | Compile ... what is selected in "Java Platform" field ?
Comment 3 abien 2013-09-25 15:27:15 UTC
(In reply to Marian Mirilovic from comment #2)
> What do you mean by "Although Java 8 is selected..." ?
> 
> Go to Project | Properties | Compile ... what is selected in "Java Platform"
> field ?

Java 8 of course :-). 

I think the issue is the path. NetBeans probably uses the JDK visible in JAVA_HOME for maven compilation and does not change that with this setting mentioned above. My JAVA_HOME points to JDK 1.7.

Before I start maven from command line (without NB) I point to JDK 1.8 and it works then.
Comment 4 Milos Kleint 2013-09-26 12:52:44 UTC
(In reply to abien from comment #3)
> (In reply to Marian Mirilovic from comment #2)
> > What do you mean by "Although Java 8 is selected..." ?
> > 
> > Go to Project | Properties | Compile ... what is selected in "Java Platform"
> > field ?
> 
> Java 8 of course :-). 
> 
> I think the issue is the path. NetBeans probably uses the JDK visible in
> JAVA_HOME for maven compilation and does not change that with this setting
> mentioned above. My JAVA_HOME points to JDK 1.7.
> 
> Before I start maven from command line (without NB) I point to JDK 1.8 and
> it works then.


The current algorith is following.

1. when a java platform is selected in the project UI, it's used.
2. if not and JAVA_HOME is defined, then it's used.
3. as a fallback default platform used to run the IDE is used.

oh actually there's 0. if Env.JAVA_HOME= property is used in the action execution props, it's used. It has highest priority to be able to override jdk usage for single action execution.

effectively a non-project based execution (typically just new project creation) will skip step 1. and only rely on 2+3. That way it can use different jdk tha project based executions.
Comment 5 Milos Kleint 2013-09-26 13:06:14 UTC
BTW does the initial line of the output in the IDE mention the JAVA_HOME env var? does it point to a valid 1.8 jdk folder?

one thing that could be wrong is this code:
getJavaPlatform().findTool("java") - the java platform manager doesn't find the java tool or..
getJavaPlatform().getInstallFolders() - it's install folders don't contain the returned fileobject for java tool.

It could be that our code is wrongly handling jdk on mac and fails in one of these methods. Then you should be seeing jdk 1.7 in the build output's header. As that's the default we fall back.
Comment 6 Jaroslav Tulach 2013-09-26 14:04:36 UTC
I can confirm the bug is real, Adam showed it to me yesterday. I tried to make it go away (bundled vs. unbundled maven, clean userdir), but no luck.

(In reply to Milos Kleint from comment #5)
> BTW does the initial line of the output in the IDE mention the JAVA_HOME env
> var? 

Yes, it is there.

> does it point to a valid 1.8 jdk folder?

No, it...

> Then you should be seeing jdk 1.7 in the build output's header. 

...shows that JAVA_HOME is set to JDK7 folder.
Comment 7 Milos Kleint 2013-09-27 06:10:23 UTC
I'm having bit of a problem with the jdk installations.
1. installing 1.8 sort of make it the default no matter what (I've installed 1.7_40 afterwards but still 1.8 is the default jdk even though just early access)
2. googling around I found http://docs.oracle.com/javase/7/docs/webnotes/install/mac/mac-jdk.html but even though setting JAVA_HOME env var to 1.7 works for the cmd line (eg java -version), netbeans seems to keep on picking up jdk 1.8.
3. So I've edited the netbeans.conf file and that finally makes netbeans pick up 1.7.

Then when I set jdk8 as java platform for a project and run a build, the output correctly points to jdk8 JAVA_HOME.

in what way is your setup different? I'm on osx 10.8.5
Comment 8 abien 2013-09-28 00:30:43 UTC
I'm setting the JAVA_HOME in ~/.profile. (.zprofile in my case)

I actually have to. I have to use Java 7 for my daily work. I'm using Java 8 currently for evaluation only,..
Comment 9 Milos Kleint 2013-09-28 06:30:14 UTC
(In reply to abien from comment #8)
> I'm setting the JAVA_HOME in ~/.profile. (.zprofile in my case)
> 
> I actually have to. I have to use Java 7 for my daily work. I'm using Java 8
> currently for evaluation only,..

and netbeans picks it up? I've added JAVA_HOME to my .profile, restarted but netbeans continued to use jdk8. That's the reason I've already once just deleted jdk8 after quick evaluation.
Comment 10 Milos Kleint 2013-12-09 11:17:13 UTC
I've workarounded my netbeans startup problem with installing 1.8 only after running netbeans.

and I cannot really reproduce your problem on my computer.
1. netbeans running on 1.7_40
2. just building the project fails as the jdk used is the IDE's jdk (1.7_40), That's correct
3. I've created a Java paltform for 1.8 and set it in the project's Compile panel. (new file nbconfiguration.xml is created with <netbeans.hint.jdkPlatform>JDK_1.8</netbeans.hint.jdkPlatform> property). 
Then the build is started with jdk 1.8 correctly.

I was not able to find this property in the codebase. (no netbeans.hint in effective pom) neither was this nb-configurations.xml file around before. So I'm not sure how you setup the jdk 8 for use in the project. 

The way it should be is to either set the jdk1.8 in all project's customizers or put the netbeans.hint.jdkPlatform property in the parent pom. When someone without the jdk1.8 platform opens your projects, we ill notify him/her that it's necessary to define a java platform with given name.

PS: I had JAVA_HOME set to 1.7_40
Comment 11 jeffsui 2014-05-15 20:24:10 UTC
I have this problem with netbeans 8