Target JDK
Target JDK for Java Applications
Can I run NetBeans ide using one version of jdk but target other versions of jdk, while developing standalone java applications?
In general, the answer is 'Yes'.
As an example, it is possible to run the ide using jdk1.6 but develop applications that run on jdk1.5 or later as follows:
- Right-click on the project and select 'Properties'
- In the project properties dialog. move to the 'Sources' category.
- Select the desired version (example: JDK 5) in the 'Source/Binary format' drop-down field and click OK.
From http://java.sun.com/javase/6/docs/technotes/tools/windows/javac.html#options
Note: Even though java compiler itself allows setting different values for source and target jdk values, NetBeans ide allows only setting them both to the same value.
If you are not using Group Layout, the above is all you need to do.
Group Layout
For swing applications using Group Layout, there is one more caveat, if the ide is run under jdk1.6.
Group Layout was not part of jdk1.5. NetBeans matisse introduced GroupLayout as a library for jdk1.5 , under org.jdesktop.layout.GroupLayout package structure. The package was later made part of JDK itself under javax.swing package in jdk1.6.
To generate programs that use GroupLayout and target jdk1.5 and later:
- In 'Tools | Options | Advanced Options | Options | Editing | GUI Builder' , set the 'Layout Generation' style to 'Swing Layout Extensions Library'.
- Right-click on 'Libraries' node in the project, select 'Add Library' and add 'Swing Layout Extensions' library to the project.
To generate programs that use GroupLayout and target jdk1.6 and later:
- In 'Tools | Options | Advanced Options | Options | Editing | GUI Builder' , set the 'Layout Generation' style to 'Standard Java 6 Code'.
- Ensure that 'Swing Layout Extensions' library is not part of the project (thus ensuring it will not be packaged in the final application jar file).
Notes
The above methods only work well for new forms. If a project containing forms that have already been developed using 1.5 (with org.jdesktop.layout packages) is later moved to jdk1.6 , there may be issues.
Links
Refer to the following links that discuss this issue for more info:


And, if you need to have your GUI app runnable on older VMs (1.4, 1.5) but you only want to distribute one single jar file, take a look at this FAQ entry for how to include the Swing layout extension in your own jar file: http://wiki.netbeans.org/FaqPackagingMatisseBasedProjects
Posted by John on January 28, 2008 at 11:27 PM PST #
You are absolutely correct - this works fine for new forms. However, when attempting to regenerate an existing form (previously targeted for 1.6), NONE of the layout is done using the org.jdesktop stuff.
So, effectively, not only is it a manual operation to downconvert, but I cannot use Matisse ever again because it (for some reason I cannot determine) resets the manually-converted layout classes BACK to javax.swing. Ugh.
Posted by Chris on May 25, 2008 at 10:43 AM PDT #
Follow up to previous comment:
Setting the global (i.e., default option) for code generation can be tweaked for individual (pre-existing) forms by following the advice here:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=5134912
PLEASE include the link here, as this page Googles better, but that page solve my issue! :-)
Thanks,
Chris
Posted by Chris on May 25, 2008 at 10:55 AM PDT #
I have added the link 'http://forum.java.sun.com/thread.jspa?forumID=57&threadID=5134912' as suggested, to the links section at the bottom of the blog entry. Thanks for the suggestion.
Posted by Karthik on May 26, 2008 at 01:49 PM PDT #