Using an IDE to work on the Java library
Bradford Wetmore
bradford.wetmore at oracle.com
Tue Jun 13 02:06:45 UTC 2017
Hi Andrew (and others),
On 6/5/2017 9:30 AM, Andrew Haley wrote:
> Sorry for what must seem like a newbie question...
Great question, as I *MUCH* prefer an IDE to System.out.println(). ;)
> ...deleted... > I suppose there must be some way to create a Project for an IDE, so
> that debugging the standard library is easy. Is there some advice
> around somewhere? What do people do?
Ok, I'll throw out my approach, which works well for me.
Note: I personally haven't looked at the included netbeans projects
recently as they didn't work years ago, and I have a solution that works
for me now.
--begin---
Here's something that might help with JDK 9 library development. I've
been able to get development builds of Netbeans 9 running to debug my
JDK 9 libraries, and while there are still some sharp edges (and dull
ones), it's been nice having a real debugger that understands modules.
(JDK 8.2 can also be used with more setup, but it doesn't understand
modules.)
I thought I'd share my process, since some folks have asked. Please
understand, I'm not a Netbeans power user, I'm just sharing what has
worked for me in hopes this might save you some time.
1. Build a current JDK
% hg clone http://hg.openjdk.java.net/jdk9/dev
% cd dev
% bash ./get_source.sh # add closed source if possible/desired.
% bash configure --enable-debug -- \
--with-default-make-target=exploded-image ...other options...
(--with-output-sync=recurse is a good idea)
% cd build/*-normal-server-fastdebug/
% make LOG=debug
2. Download the "OS Independent Zip" JDK 9 build of NetBeans.
http://netbeans.org
Download
Development
Platform: OS Independent Zip
Download
I had problems with the Windows Netbeans 9 build and missing Netbeans
classes [1], that's why I'm suggesting the OS Independent Zip.
% unzip netbeans-trunk-nightly-*-javase.zip
If you are using windows, you'll need to make the .exe/.dll bits executable:
% cd netbeans*
% find . -type f -name '*.exe' -exec chmod +x {} \;
% find . -type f -name '*.dll' -exec chmod +x {} \;
Be sure to have a JDK 8 build for the jdkhome. If NB can't find a JDK 8
in your path, you can hardcode it in etc/netbeans.conf:
netbeans_jdkhome="d:\java\bootdirs\jdk1.8.0_112"
3. Start NetBeans.
% bin/netbeans # Solaris/Linux/MacOS/etc.
or
% bin/netbeans64.exe # Windows
4. Install Jan Lahoda's (Oracle JDK/Netbeans) "JDK Project for
NetBeans" plugin. Also "JTReg Support" if you are using JTReg.
. In Tools->Plugins menu go to Settings
. Click Add button
. In the URL paste:
http://lahoda.info/hudson/job/nb-jdk-project/lastSuccessfulBuild/artifact/build/updates/updates.xml
. In Available plugins click “Check for Newest” to refresh the list.
. Select both “JDK Project for NetBeans” and "JTReg Support"
. Press "Install" button and follow the Wizard steps.
Restart NB 9.
5. Add your JDK 9 exploded build as a Java Platform
. Tools->Java Platforms->Add Platform
. Select "Java Standard Edition", Next
. /export/home/me/build/*-normal-server-fastdebug/jdk
. Pick a platform name. Do not add sources, they will be
found by the JDK Project (above).
(gensrc/shared/platform/closed)
. Finish
6. Navigate and open to the Java modules you'll be using. e.g.
jdk/src/java.base
jdk/src/jdk.crypto.cryptoki
The very first time you open the module, it will take a couple minutes
to scan through everything (source/binary/etc). Restarts are faster
after things are cached.
7. Next, depending on whether you'll debug a standalone app or a JTREG
test from the test directories:
7a. Standalone: create a test project app as normal, then select the
JDK 9 platform.
. Right click on project, select Properties.
. Choose libraries, select the platform you just created.
7b. JTREG: In the module you opened (above), navigate to the jdk test
directory. e.g.
${jdkRoot}/jdk/test
NOTE WELL: The JTReg plugin understands the JTReg directives, however
(currently) debugging a JTReg test will trigger a remake of the
entire(!) JDK platform. On my Windows machine, an incremental make
takes about three minutes before the test is compiled and the Green
Debug bar is displayed. Turn this behavior off by unselecting the
OpenJDK Property "Build before running tests."
It will take a while to scan through the test directories
(source/binary/etc). Restarts are faster as things are cached.
8. Set a break point in your app and start debugging. You should be
able to "Step In (F7)" to the JDK library code.
9. If you make any changes (think/edit/compile) to your JDK code, I
suggest stopping the debugger, then use a separate window to do the
make. For a simple rebuild of the classes in java/security +
sun/security, I do:
# cwd: build/*-normal-server-fastdebug
% make LOG=debug \
JDK_FILTER=java/security,sun/security \
java.base-java-only # or java.base-only
Netbeans will notice any changes and reload as needed. Then restart the
debugger.
I would like to make a wiki page with this info at some point, so if you
have any comments, let me know.
Good luck,
Brad
[1] https://netbeans.org/bugzilla/show_bug.cgi?id=268055
---end---
More information about the jdk10-dev
mailing list