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.
NetBeans uses JDK version that it is running on for running ANT tasks and not the project specific JDK version. For example NetBeans is running on JDK 1.6 and the project is using JDK 1.5, now I expect to see the ANT using JDK 1.5 to compile and run the project but NetBeans uses JDK 1.6 to run ANT.
As designed. NetBeans runs Ant in-VM. All the Java-platform-related tasks (<javac>, <java>, ...) in standard build scripts are configured to use the corresponding tools from the JDK associated with the project.
not for free-form project, no. I'll come back with details, if Masoud will not provide them faster. It's getting really late here, and I have to rest.
I tried to reproduce the problem, but no success. java and javac are executed by the platform set in project properties specific to project exactly as Jesse described. If you are able to reproduce other behavior, please provide very precise steps to reproduce and self contained test project. Thanks.
Sorry, but I don't have the time needed to setup the project. If you have already an example of imported web application to a Free-Form project, then all you need to do is: 1. Have the IDE (NB 6.5RC1) run on jdk 6 update 10 2. Have the project's Java platform set on JDK 5 2. Put the uploaded file (ClobWrapper) in your source 3. Your ant build file should have a task that compiles you source (among others, ClobWrapper) In my project, which is big, ClobWrapper doesn't get compiled, because JDK 6's java.sql.Clob has a few new methods which are not implemented by ClobWrapper (this being based on JDK 5's java.sql.Clob). That is the way I found out the NB 6.5RC1 doesn't use the project's platform, but the platform on which the IDE runs (JDK 6). I verified this by changing the path in netbeans.conf to jdk 5. Doing this, the project compiled successfully. As a side note, the IDE locks the files in WEB-INF/lib, which is ugly, my ant task being unable to clean up/recreate WEB-INF. The locking occurs right after the start up.
Created attachment 72521 [details] java source that doesn't get compiled
Working fine for me in a post-6.5 dev build running in JDK 6u10 on Ubuntu. Made a new "Skeletal Freeform Project" (a simple template available if you install the module Freeform Project Extras from dev AU). Added your source file to default package. Editor shows errors as expected. In Properties, under Java Sources Classpath, set Java Platform to a JDK 5 installation I had configured, and clicked OK. Error badges disappeared from editor. Clicked Build. Ant process succeeded and JAR was created. So please provide complete steps to reproduce if you still can. You will also want to run Ant in Verbose (or Debug) mode and figure out why nbjdk.xml/jdk.xml is not working.
Tried the same on NetBeans 6.5 RC1 and own freeform project with your file and got the same results as Jesse - project compiles with JDK 1.5 and do not compile with JDK 1.6. Sorry, but until you provide self-contained test case I cannot identify any problem.
Are you sure you ran NB on jdk 6, and set the project to use jdk 5? These 2 conditions must be met simultaneously. I retested on the latest build (Build 200810230201), and I got the same result. I'm sorry, but I can't provide you the web app I imported, because I'm not allowed to do that. All I know is it happens, and I can't use NB for developing that application. (I noticed that locking problem I mentioned in my previous post has gone. At least now the task can delete those files.) I also put the verbosity of Ant to Verbose, and got this: Detected Java version: 1.6 in: C:\Program Files\Java\jdk1.6.0_10\jre Detected OS: Windows XP My JAVA_HOME is set to jdk 5. My java platform is set to JDK 5, in the project. NB runs on JDK 6. I don't know what else can I do. If you need anything else, I will provide (logs, etc).
java/freeform is most likely the correct component. The Ant module simply runs whatever is requested of it. It is java.freeform which handles the project's Java platform selection. "Are you sure you ran NB on jdk 6, and set the project to use jdk 5?" - yes, and this functionality has been part of NB for years now. I understand that you may be working on a confidential codebase and cannot attach your real project. But you will need to come up with some minimal dummy project with similar structure which displays the problem. You can run in verbose mode and check the logs. nbproject/nbjdk.xml should be being run as the entry script (wrapping your primary.xml so as to presetdef various tasks to take the correct JDK). nbjdk.properties should define the platform for the project as JDK 5, and $userdir/build.properties should define the actual location of that JDK. jdk.xml should be defining the bootclasspath and such things. P1 for bugs with no workaround. This would have two (if reproducible): run IDE on JDK 5; or edit <javac> in your own build script to explicitly run the javac binary from a JDK 5 installation (which is essentially what jdk.xml silently does on your behalf).
Created attachment 72618 [details] test project
Created attachment 72619 [details] test project
First, sorry for uploading twice. I tried to stop the upload, but it didn't work, it seems. The zip contains the Test application, and a TestNB netbeans project. It's already set up, so you don't have to do anything else. The only source compiles if you right click on it and run the context menu's Compile File, or press F9 while in the file. BUT, go to the build.xml, expand it, right click the compile task, and choose Run Target. You'll get what I was trying to explain till now. I hope it is more clear now. Remember to have the IDE running on jdk 6. The project is set to jdk5 by me.
The project is set to have not only the source level to jdk5, but the platform too. As it says there (project properties->Java Sources Classpath), "the platform is used by code completion and similar features and is also used for running the Ant script from the IDE". I think that it says about the IDE's own generated build file, not the project's own build file, which is there and you can see it. I expect that my build file to be also run on jdk 5.
You need to go through nbjdk.xml in order for the Java platform setting to be honored. This is done automatically when you invoke a build through the IDE's normal Build action (or Compile File, etc.), but not if you explicitly run a target directly from the build.xml, unless your build.xml happens to request the configured Java platform. The easiest way to configure your build script to be able to use a configured Java platform is <import file="nbproject/jdk.xml"/> and then add -jdk-init as a dependency to relevant targets. This is essentially all nbjdk.xml does.
Quoting excerpts from a private email (please use IZ for discussions): > IntelliJ Idea has a setting for your personal build.xml, that allows > you to choose the jdk platform on which your own ant targets are run. Yes, IDEA runs Ant as an external process, in which case it is trivial to just choose to run that with a different JDK. NB runs Ant in-process (for various reasons, especially because NB features rely heavily on monitoring fine-grained events fired by Ant that do not necessarily appear in text output). When running in-process, it is impossible to have Ant itself use a different JDK than NB. Rather, Java-related Ant tasks can be configured to compile, run, etc. using a particular platform. > You could say that I could run NB directly on jdk 5. I do not recommend this, just mentioning it as one possible workaround. The supported way is to import nbjdk.xml and depend on -jdk-init - or, equivalently, to specify a Java platform directly in your script. Either way makes the JDK dependency explicit, eliminating a silent environmental dependency of your script. Currently nbjdk.xml is used _automatically_ only in the case of targets bound to IDE actions. For automatic projects (the possible replacement for freeform projects) I will be considering ways to implicitly load the equivalent of nbjdk.xml when running any target from any build script located within the project's source tree. Such a feature could probably be backported to the freeform project type, though it is a little more complex in that case as it might be necessary to also suppress the current system.
See issue #151371.
I tried the supported workaround, with the nbjdk.xml, and the jdk.xml. NB (Build 200810271401) I imported the xml files, one at a time. I have to say that the nbproject folder is stored outside my project's root, in its own folder, so I imported it by giving the relative path, like ../external_folder/nbproject. NB confirmed that the xml was seen, and displayed the targets with gray. I also set the depend attribute: <target depends="-jdk-init" name="project-setup" description="Create the WEB-INF dir and copies the relevant files from the modules"> After doing that, I ran the target, but with the same outcome. So it seems that this workaround doesn't work, unless I did something wrong.
In the case of an externally located nbproject dir, you would need to adjust the line at the top of nbjdk.xml <property file="nbproject/nbjdk.properties"/> to refer to the external location. (For imported scripts, basedir is not modified, so paths are relative to the _original_ script.) NB running an action from the GUI directly calls an nbjdk.xml target (which calls your original target in turn) so it does not run into this complication.