I wish to debug a Java class that I call from Matlab. Is
there any way to connect Eclipse (or something else) to set
debuggable breakpoints in my Java code?
(simple system.out.println works of course, but I need a
more heavy-duty debugger)
"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
<fb1gnk$5o4$1@fred.mathworks.com>...
> Hello all,
>
> I wish to debug a Java class that I call from Matlab. Is
> there any way to connect Eclipse (or something else) to set
> debuggable breakpoints in my Java code?
>
> (simple system.out.println works of course, but I need a
> more heavy-duty debugger)
>
> Thanks,
> Yair Altman
Hi Yair,
I just figured out how to do it for MATLAB 7R14 (should work
for later versions) and Eclipse (I'm using JBuilder 2007,
which is Eclipse 3.2.2). Here is how:
1) Create a Eclipse project (you must use JDK 1.5 or above)
to include the source code of your java classes, remember
the directory where you put the output classes when you
define your project.
2) Add the following flags in java.opts in directory
%MATLAB_ROO%\bin\arch.
3) In your eclipse project, define a debug configuration.
For me, I've to add a "Remote Java Application"
configuration. In the "Connection Type" field, use "Standard
(Socket Attach)". Then use "localhost" for field "Host" and
"1044" for "Port".
4) Then launch MATLAB, make sure you add the directory of
the output classes from step 1 into MATLAB's javaclasspath.
You can use either static or dynamic classpath here.
5) Then debug the "Remote Java Application" on the Eclipse
side, put a break point in your java code and instantiate or
execute your java code from within MATLAB. You should see
the breakpoint popping up when MATLAB calls java.
I just found out that port 1044 is very popular (used by
many software) which causes MATLAB not to launch if there is
any other process is using the port. So changing it to
something else would be a good idea.
"Ed Yu" <ekyu88@hotmail.com> wrote in message
<fqrpem$r2s$1@fred.mathworks.com>...
> I just found out that port 1044 is very popular (used by
> many software) which causes MATLAB not to launch if there is
> any other process is using the port. So changing it to
> something else would be a good idea.
Also a good idea to use the follow flag to disable JIT compiler:
"Ed Yu" <ekyu88@hotmail.com> wrote in message <fiptu4
$l3b$1@fred.mathworks.com>...
> "Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in
message
> <fb1gnk$5o4$1@fred.mathworks.com>...
> > Hello all,
> >
> > I wish to debug a Java class that I call from Matlab. Is
> > there any way to connect Eclipse (or something else) to
set
> > debuggable breakpoints in my Java code?
> >
> > (simple system.out.println works of course, but I need a
> > more heavy-duty debugger)
> >
> > Thanks,
> > Yair Altman
>
> Hi Yair,
>
> I just figured out how to do it for MATLAB 7R14 (should
work
> for later versions) and Eclipse (I'm using JBuilder 2007,
> which is Eclipse 3.2.2). Here is how:
>
> 1) Create a Eclipse project (you must use JDK 1.5 or
above)
> to include the source code of your java classes, remember
> the directory where you put the output classes when you
> define your project.
>
> 2) Add the following flags in java.opts in directory
> %MATLAB_ROO%\bin\arch.
>
> -Xdebug
> -
Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n
>
> 3) In your eclipse project, define a debug configuration.
> For me, I've to add a "Remote Java Application"
> configuration. In the "Connection Type" field,
use "Standard
> (Socket Attach)". Then use "localhost" for field "Host"
and
> "1044" for "Port".
>
> 4) Then launch MATLAB, make sure you add the directory of
> the output classes from step 1 into MATLAB's
javaclasspath.
> You can use either static or dynamic classpath here.
>
> 5) Then debug the "Remote Java Application" on the Eclipse
> side, put a break point in your java code and instantiate
or
> execute your java code from within MATLAB. You should see
> the breakpoint popping up when MATLAB calls java.
>
> Have fun!
Works quite well, thanks! Also, helps to remember to
compile with -g flag as usual, to generate the debugging
info. (javac -g YourBuggyCode.java)
This seems like a good idea, but it didn't work for me. I believe I followed the instructions, but when I run the launcher in Eclipse, I get a dialog saying:
Failure to connect to remote VM. Connection refused.
Connection refused: connect
This happens whether Matlab is started before the launcher or after.
I made the file java.opts in C:\Program Files\Matlab\2007a\bin\win32.
Possible reasons:
1. I tried putting the opts on one line or on multiple lines as in the forum message. I also tried with and without -Djava.compiler=NONE. (So should it be one line or multiple lines? I can't find any good documentation on java.opts.) This is my current choice:
Try the following in java.opts:
-agentlib:jdwp=transport=dt_socket,address=5678,server=y,suspend=n
The -Xrunjdwp option is deprecated.
-AndyJ
"Kenneth " <nomail@email.com> wrote in message
news:gap9ke$gne$1@fred.mathworks.com...
> This seems like a good idea, but it didn't work for me. I believe I
> followed the instructions, but when I run the launcher in Eclipse, I get a
> dialog saying:
>
> Failure to connect to remote VM. Connection refused.
> Connection refused: connect
>
> This happens whether Matlab is started before the launcher or after.
>
> I made the file java.opts in C:\Program Files\Matlab\2007a\bin\win32.
>
> Possible reasons:
>
> 1. I tried putting the opts on one line or on multiple lines as in the
> forum message. I also tried with and without -Djava.compiler=NONE. (So
> should it be one line or multiple lines? I can't find any good
> documentation on java.opts.) This is my current choice:
>
> -Xdebug
> -Xrunjdwp:transport=dt_socket,address=5678,server=y,suspend=n
> -Djava.compiler=NONE
>
> 2. I am using 7.4.0.287 (R2007a). The forum says MATLAB 7R14. (I don't
> understand this numbering.) Is my version too old?
>
> 3. I am using Eclipse 3.3.2.
>
> 4. I have tried several different ports. 1044 is not currently in use on
> my machine, however.
>
> Any help would be appreciated. I've run out of ideas, and I can't find
> this documented anywhere else.
>
> Thanks.
Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central. Read the complete Disclaimer prior to use.