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 151078 - Project specific JDK is not used for running ANT
Summary: Project specific JDK is not used for running ANT
Status: RESOLVED INVALID
Alias: None
Product: java
Classification: Unclassified
Component: Freeform (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P2 blocker (vote)
Assignee: Milan Kubec
URL:
Keywords:
Depends on: 154819
Blocks:
  Show dependency tree
 
Reported: 2008-10-22 23:04 UTC by kalali
Modified: 2008-12-05 22:46 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
java source that doesn't get compiled (1.54 KB, text/plain)
2008-10-23 10:01 UTC, cbulcu
Details
test project (7.29 KB, text/plain)
2008-10-24 17:22 UTC, cbulcu
Details
test project (7.29 KB, application/octet-stream)
2008-10-24 17:22 UTC, cbulcu
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kalali 2008-10-22 23:04:29 UTC
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.
Comment 1 Jesse Glick 2008-10-22 23:27:36 UTC
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.
Comment 2 cbulcu 2008-10-22 23:58:38 UTC
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.
Comment 3 Milan Kubec 2008-10-23 07:45:07 UTC
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.
Comment 4 cbulcu 2008-10-23 09:59:40 UTC
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.
Comment 5 cbulcu 2008-10-23 10:01:57 UTC
Created attachment 72521 [details]
java source that doesn't get compiled
Comment 6 Jesse Glick 2008-10-23 15:10:38 UTC
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.
Comment 7 Milan Kubec 2008-10-23 15:56:47 UTC
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.
Comment 8 cbulcu 2008-10-23 19:36:17 UTC
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).
Comment 9 Jesse Glick 2008-10-23 20:52:37 UTC
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).
Comment 10 cbulcu 2008-10-24 17:22:10 UTC
Created attachment 72618 [details]
test project
Comment 11 cbulcu 2008-10-24 17:22:20 UTC
Created attachment 72619 [details]
test project
Comment 12 cbulcu 2008-10-24 17:29:56 UTC
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.
Comment 13 cbulcu 2008-10-24 17:35:47 UTC
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.
Comment 14 Jesse Glick 2008-10-24 19:05:02 UTC
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.
Comment 15 Jesse Glick 2008-10-25 18:11:18 UTC
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.
Comment 16 Jesse Glick 2008-10-25 18:21:46 UTC
See issue #151371.
Comment 17 cbulcu 2008-10-27 23:01:56 UTC
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.
Comment 18 Jesse Glick 2008-10-28 04:28:01 UTC
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.