Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Debugging java class called from Matlab

Subject: Debugging java class called from Matlab

From: Yair Altman

Date: 28 Aug, 2007 15:58:44

Message: 1 of 10

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

Subject: Debugging java class called from Matlab

From: Ed Yu

Date: 30 Nov, 2007 21:05:08

Message: 2 of 10

"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!

Subject: Debugging java class called from Matlab

From: Ed Yu

Date: 7 Mar, 2008 16:11:02

Message: 3 of 10

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.

Subject: Debugging java class called from Matlab

From: Ed Yu

Date: 16 Apr, 2008 16:19:03

Message: 4 of 10

"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:

-Djava.compiler=NONE

Subject: Debugging java class called from Matlab

From: Aleks

Date: 1 Aug, 2008 15:32:02

Message: 5 of 10

"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)

Subject: Debugging java class called from Matlab

From: siva

Date: 4 Aug, 2008 08:46:46

Message: 6 of 10

Hi,

Please help me in getting the second point mentioned above. I am not able to find the path %MATLAB_ROO%\bin\arch.
Please explain me more....

Thanks in advance

Subject: Debugging java class called from Matlab

From: Kenneth

Date: 16 Sep, 2008 21:49:02

Message: 7 of 10

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.

Subject: Debugging java class called from Matlab

From: Andy Johnson

Date: 25 Sep, 2008 18:31:46

Message: 8 of 10

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.

Subject: Debugging java class called from Matlab

From: Kenneth Evans

Date: 25 Sep, 2008 21:04:01

Message: 9 of 10

Andy,

When I went to try what you suggested, I found the real problem. I had put java.opts in the wrong bin/arch. I do apologize.

It is apparently OK to put the opts on separate lines. This is what I am now using:

-Xdebug
-agentlib:jdwp=transport=dt_socket,address=5678,server=y,suspend=n
-Djava.compiler=NONE

It is truly awesome. Thanks to you and the others for working this out.

     -Ken

Subject: Debugging java class called from Matlab

From: Holger

Date: 13 Oct, 2008 10:08:01

Message: 10 of 10

Hi.

For debugging java classes: Does anybody know if / how it is possible to connect Eclipse 3.2.1 and MATLAB 6.0.0.88 (R12) on Windows ?

Any help would be really appreciated.

BR,
Holger

Tags for this Thread

Everyone's Tags:

java(3), eclipse(2), java debug(2), debug(2)

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
debug Kenneth Evans 16 Sep, 2008 17:50:20
java debug Kenneth Evans 16 Sep, 2008 17:50:20
eclipse Kenneth Evans 16 Sep, 2008 17:50:20
java Kenneth Evans 16 Sep, 2008 17:50:20
java Ed Yu 16 Apr, 2008 12:20:21
debug Ed Yu 16 Apr, 2008 12:20:21
eclipse Ed Yu 16 Apr, 2008 12:20:21
java debug Ed Yu 30 Nov, 2007 16:05:21
java Yair Altman 28 Aug, 2007 12:00:26
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

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.
Related Topics