📄 ch10s14.html
字号:
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Integrating NetBeans/Forte for Java Community Edition with JBoss
for source level debugging</title><link rel="stylesheet" href="styles.css" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/styles.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets Vimages/callouts/"><link rel="home" href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html" title="JBoss 3.0 Documentation"><link rel="up" href="ch10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10.html" title="Chapter 10. Development Tools and IDE Integration"><link rel="previous" href="ch10s10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10s10.html" title="
 How to Run and Debug EJBs using jBoss 2.2.2 inside of 
 Visual Age for Java version 3.5 (patch 2)
"><link rel="next" href="ch10s25.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10s25.html" title="Using Verifier in Ant"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="jboss.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/jboss.gif" border="0"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch10s10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10s10.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch10s25.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10s25.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table><div class="section"><a name="d0e7205"></a><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="d0e7205"></a>Integrating NetBeans/Forte for Java Community Edition with JBoss
for source level debugging</h2></div></div><p>Author:<span class="author">Jay Walters</span>
<tt><<a href="mailto:jwalters@computer.org">jwalters@computer.org</a>></tt>
</p><div class="section"><a name="d0e7219"></a><div class="titlepage"><div><h3 class="title"><a name="d0e7219"></a>Purpose</h3></div></div><p>This howto is a first pass at illustrating the procedures required to
use NetBeans to develop and debug EJBs running within JBoss. It will also
discuss how to make the JBoss source available so that debugging can include
JBoss code. It is not the purpose of this howto to describe how to develop
and debug the JBoss code.
</p><p>Because Sun's Forte for Java and NetBeans share much of their source
code, this howto should be applicable to users in that environment as well.
</p></div><div class="section"><a name="d0e7226"></a><div class="titlepage"><div><h3 class="title"><a name="d0e7226"></a>Install the JBoss Server</h3></div></div><p>
For the purpose of this howto, I installed the JBossTomcat release version
2.4.4/3.2.3 into /opt/appserver on my linux box. If you translate the steps
into Windows NT/2000 you can also debug JBoss apps using Netbeans there.
Download it from http://www.jboss.org and select the binary link from the
page. Don't worry about downloading a binary package, when all you want is
the source code; the binary package also contains the source code used for
building.
</p></div><div class="section"><a name="d0e7231"></a><div class="titlepage"><div><h3 class="title"><a name="d0e7231"></a>Create a NetBeans Project</h3></div></div><p>Start NetBeans, I used NetBeans 3.3 while writing this howto. The first
step is to create a new project or open an existing project. You create a new
project from the Project -> Project Manager menu selection. This dialog will
show a list of your projects like:
</p><div class="mediaobject"><img src="netbeans-project.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/netbeans-project.png"></div></div><div class="section"><a name="d0e7239"></a><div class="titlepage"><div><h3 class="title"><a name="d0e7239"></a>Mount the JBoss client jarfiles</h3></div></div><p>
This is a bit tedious, though it's not too bad. Once you have opened your
project you should go to the explorer window and select the FileSystems tab.
Either right click on the FileSystems entry in the explorer window, or choose
File -> Mount Filesystem and pick mount jar. Use the browser or type in the
path for the following jar files: jboss/lib/ext/jboss-j2ee.jar and
jboss/lib/jboss-jdbc_ext.jar. If you are using JBossSX security then you'll
also need to add additional jar files jboss/lib/jaas.jar,
jboss/lib/jboss-jaas.jar and jboss/lib/ext/jbosssx.jar.
If you are using JMS from your client you'll also need to add
jboss/lib/ext/jbossmq-client.jar. Once you have added all these jar files a
if you don't want them to show in the explorer you can right click on them
one by one and from the properties panel select hidden=true.
</p><p>
At this point you need to add any other jar files specific to your app which
need to be available to compile your project, e.g. log4j.jar if you are using
the Apache logging framework.
</p></div><div class="section"><a name="d0e7246"></a><div class="titlepage"><div><h3 class="title"><a name="d0e7246"></a>Complete your project and build your jar/war files</h3></div></div><p>
Now you should be able to mount the directory containing your source
code and compile it by right clicking on the root package and selecting compile
all.
</p><p>
In order to build a jarfile from which to deploy your EJBs you'll need to add
a new jar packager element to your project. Select File -> New and then
from the Wizard select Jar Packager -> Jar Contents. This will take you
into the Jar Packager wizard. It will allow you to specify the name of the
jarfile, select and filter the contents of mounted filesystems for inclusion
in the jarfile, and the output directory for the jarfile.
</p><p>
I have never seen POSIX filters before myself, there is good help available
within NetBeans. The short version is that a filter to include .class files
is \.class$. You could include .class and .xml files with a filter like
(\.class$)|(\.xml$). See the online help for more details.
</p><p>You will need to make
sure that you include all required .class files as well as deployment
descriptors in the META-INF directory. You right click on the Jar Contents
and select "compile" to create the jar file.
</p><p>
After you have built the deployable jar file or war file you can deploy it into
your JBoss server. If you want NetBeans to deploy the jar/war file for you
then make the output location the jboss/deploy directory and you'll be on your
way. Otherwise you'll need to manually copy it from where NetBeans writes it
to the jboss/deploy directory.
</p></div><div class="section"><a name="d0e7259"></a><div class="titlepage"><div><h3 class="title"><a name="d0e7259"></a>Setup JBoss for debugging</h3></div></div><p>Since these instructions are not for debugging JBoss so much as an
application running in JBoss, at the moment the instructions will start
JBoss from the command line and then attach the debugger. At some point in
the future we can augment these instructions with instructions to launch
JBoss from within NetBeans.
</p><p>
Make the following changes to your run.bat/run.sh file, or copy
run.bat/run.sh to a new file debug.bat/debug.sh and paste the text in. This
text is the Windows version, the UNIX version should use $env-var instead of
%env-var%. Change the command line from:
</p><p><pre class="programlisting">
java %JAXP% -classpath %JBOSS_CLASSPATH% org.jboss.Main ...
</pre></p><p>to: (as a single command line)</p><p><pre class="programlisting">
java -Xint -Xdebug -Xnoagent -classpath "%JBOSS_CLASSPATH%" -Xrunjdwp:transport=dt_socket,server=y,address=12999,suspend=n org.jboss.Main %1 %2 %3 %4 %5 %6 %7 %8 %9
</pre></p><p>
The -Xint switch disables hotspot optimizations. This is not strictly
necessary, but in my testing with the Win32 JDK 1.3 the JVM seemed more
stable with this switch enabled.
</p><p>
You can of course substitute your favorite port for the 12999 in the example.
</p><p>
Once you startup JBoss then you can attach to it from NetBeans to do your
debugging. Select the Debug -> Attach menu selection in NetBeans and then
the debugger type should be default debugger JPDA. Select the SocketAttach
in the connector dropdown and then enter the port number you selected when you
edited the debug.bat/debug.sh file. The hostname should default to your local
hostname when you select SocketAttach. After you complete filling in the
debug "Attach to VM" dialog it should look something like:
</p><div class="mediaobject"><img src="netbeans-debug.png" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/netbeans-debug.png"></div></div><div class="section"><a name="d0e7283"></a><div class="titlepage"><div><h3 class="title"><a name="d0e7283"></a>Start the JBoss server</h3></div></div><p>
Start JBoss using the debug script which you previously created. Deploy the
EJBs you'd like to debug. If you want to see
your beans being instantiated by the deployer, place breakpoints on the bean
constructors (if you specified them) You will not need to have a client
running to exercise this functionality.
</p></div><div class="section"><a name="d0e7288"></a><div class="titlepage"><div><h3 class="title"><a name="d0e7288"></a>Sprinkle breakpoints throughout your EJB and or Client Code</h3></div></div><p>
Before you can debug, it is necessary to put breakpoints into your code. On
the client side you can just open up your source files and toggle breakpoints
as in any other Netbeans debugging effort. To put breakpoins into your ejb's
is different. You will need to use the loaded classes menus to select the
class and method you would like to break on. Once you have hit a break point
within the class, and the source code is displayed, then you can add
additional breakpoints. This seems to be an artifact of the class loading
scheme used by JBoss, and a problem within NetBeans where it puts a breakpoint
on the system classloader when you just open the source file and toggle a
breakpoint.
</p></div><div class="section"><a name="d0e7293"></a><div class="titlepage"><div><h3 class="title"><a name="d0e7293"></a>Start the Client Test Application</h3></div></div><p>
To really debug your beans you will need to start up a client application.
The easiest way to do this is either with a command line client, or else
with a servlet/JSP client running inside any embedded or otherwise servlet
container. One thing though, the timeouts
are somewhat short so if you spend too much time in a method within the EJB
you may find that transactions are rolled back.
</p></div><div class="section"><a name="d0e7298"></a><div class="titlepage"><div><h3 class="title"><a name="d0e7298"></a>Feedback</h3></div></div><p>
If anyone has suggestions of feedback please let me know, I can be contacted
via email at jwalters@computer.org.
</p></div></div><table border="0" cellpadding="0" cellspacing="0" height="65"><tr height="65"><td rowspan="2"><img src="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="432" height="79"></td><td rowspan="2" background="gbar.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/gbar.gif" width="100%" align="right" valign="top"><a href="index.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/index.html"><img src="doc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/doc.gif" border="0"></a><a href="ch10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10.html"><img src="toc.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/toc.gif" border="0"></a><a href="ch10s10.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10s10.html"><img src="prev.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/prev.gif" border="0"></a><a href="ch10s25.html" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/ch10s25.html"><img src="next.gif" tppabs="http://www.huihoo.org/jboss/online_manual/3.0/next.gif" border="0"></a></td></tr><tr></tr></table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -