You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@buildr.apache.org by Babu Naidu <pb...@gmail.com> on 2009/11/17 22:30:02 UTC

How to run a java test (Junit) in debug mode

Hi,

I have a junit test that I would like to debug, however I am not able to
figure out how to pass java debug options to the JVM that runs junit test or
test task. For example, I would like to run the junit test with '-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453' jvm options
and connect my IDE to it for further debugging. I tried setting JAVA_OPTS
variable, it didn't work, probably these options weren't propagated to the
JVM that ran my test as it didn't stop at a breakpoint in my test class.

Thanks
Babu

Re: How to run a java test (Junit) in debug mode

Posted by Babu Naidu <pb...@gmail.com>.
Thanks... that worked..

-Babu

On Tue, Nov 17, 2009 at 5:30 PM, Rhett Sutphin <rh...@detailedbalance.net>wrote:

> Hi Babu,
>
>
> On Nov 17, 2009, at 6:05 PM, Babu Naidu wrote:
>
>  Sorry for the confusion. I tried with just :java_args, it didn't work for
>> me. However, with JAVA_OPTS setting and :fork=false works but painful.
>>
>> I am not sure why just :java_args isn't working. I am using JDK 6 on Mac
>> OS.
>>
>
> I just noticed that you're passing the args as a single string.  You need
> to pass them as an array:
>
>  test.using :java_args => ["-Xdebug",
> "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453", "-Xms128m",
> "-Xmx256m"]
>
> Or (more rubyish):
>
>  test.using :java_args => %w(-Xdebug
> -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453 -Xms128m
> -Xmx256m)
>
> Rhett
>
>
>
>> Thanks
>> Babu
>>
>> On Tue, Nov 17, 2009 at 4:26 PM, Rhett Sutphin <rhett@detailedbalance.net
>> >wrote:
>>
>>  Hi Babu,
>>>
>>>
>>> On Nov 17, 2009, at 5:12 PM, Babu Naidu wrote:
>>>
>>> Thanks.
>>>
>>>>
>>>> I am on buildr 1.3.4 and Jruby 1.3.0 and I have  following code defined
>>>> for
>>>> a project in build file.
>>>>
>>>>   test.using :java_args => "-Xdebug
>>>> -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453 -Xms128m
>>>> -Xmx256m", :fork => false
>>>>   test.resources
>>>>
>>>>
>>>> {filter(project.path_to("src/main/resources")).into(test.resources.target).run}
>>>>   test.compile.with(projects('api'), resources)
>>>>
>>>>
>>> You need to either use java_args or fork=false -- not both.  fork=false
>>> means that the test will run in the same JVM that buildr is using,
>>> meaning
>>> it doesn't start up a new one, meaning that java_args will be ignored.
>>>
>>> Rhett
>>>
>>>
>>> =========================================================================
>>>
>>>>
>>>> It didn't work for as it didn't output that it is listening on a port
>>>> and
>>>> waiting for an IDE to connect to. It just executed my test without
>>>> stopping.
>>>> Any ideas/hints what's going on here?
>>>>
>>>> Thanks
>>>> Babu
>>>>
>>>>
>>>> On Tue, Nov 17, 2009 at 2:44 PM, Rhett Sutphin <
>>>> rhett@detailedbalance.net
>>>>
>>>>> wrote:
>>>>>
>>>>
>>>> Hi Babu,
>>>>
>>>>>
>>>>>
>>>>> On Nov 17, 2009, at 3:30 PM, Babu Naidu wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>>
>>>>>> I have a junit test that I would like to debug, however I am not able
>>>>>> to
>>>>>> figure out how to pass java debug options to the JVM that runs junit
>>>>>> test
>>>>>> or
>>>>>> test task. For example, I would like to run the junit test with
>>>>>> '-Xdebug
>>>>>> -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453' jvm
>>>>>> options
>>>>>> and connect my IDE to it for further debugging. I tried setting
>>>>>> JAVA_OPTS
>>>>>> variable, it didn't work, probably these options weren't propagated to
>>>>>> the
>>>>>> JVM that ran my test as it didn't stop at a breakpoint in my test
>>>>>> class.
>>>>>>
>>>>>> Thanks
>>>>>> Babu
>>>>>>
>>>>>>
>>>>>>  Check out this section of the docs:
>>>>>
>>>>> http://buildr.apache.org/languages.html#java
>>>>>
>>>>> You want to pass :java_args to test.using.  (Alternatively you could
>>>>> turn
>>>>> off forking and use JAVA_OPTS, but I wouldn't recommend that.)
>>>>>
>>>>> Rhett
>>>>>
>>>>>
>>>>>
>>>
>

Re: How to run a java test (Junit) in debug mode

Posted by Rhett Sutphin <rh...@detailedbalance.net>.
Hi Babu,

On Nov 17, 2009, at 6:05 PM, Babu Naidu wrote:

> Sorry for the confusion. I tried with just :java_args, it didn't  
> work for
> me. However, with JAVA_OPTS setting and :fork=false works but painful.
>
> I am not sure why just :java_args isn't working. I am using JDK 6 on  
> Mac OS.

I just noticed that you're passing the args as a single string.  You  
need to pass them as an array:

   test.using :java_args => ["-Xdebug", "- 
Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453", "- 
Xms128m", "-Xmx256m"]

Or (more rubyish):

   test.using :java_args => %w(-Xdebug - 
Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453 -Xms128m - 
Xmx256m)

Rhett

>
> Thanks
> Babu
>
> On Tue, Nov 17, 2009 at 4:26 PM, Rhett Sutphin <rhett@detailedbalance.net 
> >wrote:
>
>> Hi Babu,
>>
>>
>> On Nov 17, 2009, at 5:12 PM, Babu Naidu wrote:
>>
>> Thanks.
>>>
>>> I am on buildr 1.3.4 and Jruby 1.3.0 and I have  following code  
>>> defined
>>> for
>>> a project in build file.
>>>
>>>    test.using :java_args => "-Xdebug
>>> -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453 - 
>>> Xms128m
>>> -Xmx256m", :fork => false
>>>    test.resources
>>>
>>> {filter(project.path_to("src/main/ 
>>> resources")).into(test.resources.target).run}
>>>    test.compile.with(projects('api'), resources)
>>>
>>
>> You need to either use java_args or fork=false -- not both.   
>> fork=false
>> means that the test will run in the same JVM that buildr is using,  
>> meaning
>> it doesn't start up a new one, meaning that java_args will be  
>> ignored.
>>
>> Rhett
>>
>>
>> = 
>> = 
>> = 
>> = 
>> =====================================================================
>>>
>>> It didn't work for as it didn't output that it is listening on a  
>>> port and
>>> waiting for an IDE to connect to. It just executed my test without
>>> stopping.
>>> Any ideas/hints what's going on here?
>>>
>>> Thanks
>>> Babu
>>>
>>>
>>> On Tue, Nov 17, 2009 at 2:44 PM, Rhett Sutphin <rhett@detailedbalance.net
>>>> wrote:
>>>
>>> Hi Babu,
>>>>
>>>>
>>>> On Nov 17, 2009, at 3:30 PM, Babu Naidu wrote:
>>>>
>>>> Hi,
>>>>
>>>>>
>>>>> I have a junit test that I would like to debug, however I am not  
>>>>> able to
>>>>> figure out how to pass java debug options to the JVM that runs  
>>>>> junit
>>>>> test
>>>>> or
>>>>> test task. For example, I would like to run the junit test with  
>>>>> '-Xdebug
>>>>> -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453' jvm
>>>>> options
>>>>> and connect my IDE to it for further debugging. I tried setting
>>>>> JAVA_OPTS
>>>>> variable, it didn't work, probably these options weren't  
>>>>> propagated to
>>>>> the
>>>>> JVM that ran my test as it didn't stop at a breakpoint in my  
>>>>> test class.
>>>>>
>>>>> Thanks
>>>>> Babu
>>>>>
>>>>>
>>>> Check out this section of the docs:
>>>>
>>>> http://buildr.apache.org/languages.html#java
>>>>
>>>> You want to pass :java_args to test.using.  (Alternatively you  
>>>> could turn
>>>> off forking and use JAVA_OPTS, but I wouldn't recommend that.)
>>>>
>>>> Rhett
>>>>
>>>>
>>


Re: How to run a java test (Junit) in debug mode

Posted by Babu Naidu <pb...@gmail.com>.
Sorry for the confusion. I tried with just :java_args, it didn't work for
me. However, with JAVA_OPTS setting and :fork=false works but painful.

I am not sure why just :java_args isn't working. I am using JDK 6 on Mac OS.

Thanks
Babu

On Tue, Nov 17, 2009 at 4:26 PM, Rhett Sutphin <rh...@detailedbalance.net>wrote:

> Hi Babu,
>
>
> On Nov 17, 2009, at 5:12 PM, Babu Naidu wrote:
>
>  Thanks.
>>
>> I am on buildr 1.3.4 and Jruby 1.3.0 and I have  following code defined
>> for
>> a project in build file.
>>
>>     test.using :java_args => "-Xdebug
>> -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453 -Xms128m
>> -Xmx256m", :fork => false
>>     test.resources
>>
>> {filter(project.path_to("src/main/resources")).into(test.resources.target).run}
>>     test.compile.with(projects('api'), resources)
>>
>
> You need to either use java_args or fork=false -- not both.  fork=false
> means that the test will run in the same JVM that buildr is using, meaning
> it doesn't start up a new one, meaning that java_args will be ignored.
>
> Rhett
>
>
>  =========================================================================
>>
>> It didn't work for as it didn't output that it is listening on a port and
>> waiting for an IDE to connect to. It just executed my test without
>> stopping.
>> Any ideas/hints what's going on here?
>>
>> Thanks
>> Babu
>>
>>
>> On Tue, Nov 17, 2009 at 2:44 PM, Rhett Sutphin <rhett@detailedbalance.net
>> >wrote:
>>
>>  Hi Babu,
>>>
>>>
>>> On Nov 17, 2009, at 3:30 PM, Babu Naidu wrote:
>>>
>>> Hi,
>>>
>>>>
>>>> I have a junit test that I would like to debug, however I am not able to
>>>> figure out how to pass java debug options to the JVM that runs junit
>>>> test
>>>> or
>>>> test task. For example, I would like to run the junit test with '-Xdebug
>>>> -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453' jvm
>>>> options
>>>> and connect my IDE to it for further debugging. I tried setting
>>>> JAVA_OPTS
>>>> variable, it didn't work, probably these options weren't propagated to
>>>> the
>>>> JVM that ran my test as it didn't stop at a breakpoint in my test class.
>>>>
>>>> Thanks
>>>> Babu
>>>>
>>>>
>>> Check out this section of the docs:
>>>
>>> http://buildr.apache.org/languages.html#java
>>>
>>> You want to pass :java_args to test.using.  (Alternatively you could turn
>>> off forking and use JAVA_OPTS, but I wouldn't recommend that.)
>>>
>>> Rhett
>>>
>>>
>

Re: How to run a java test (Junit) in debug mode

Posted by Rhett Sutphin <rh...@detailedbalance.net>.
Hi Babu,

On Nov 17, 2009, at 5:12 PM, Babu Naidu wrote:

> Thanks.
>
> I am on buildr 1.3.4 and Jruby 1.3.0 and I have  following code  
> defined for
> a project in build file.
>
>      test.using :java_args => "-Xdebug
> -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453 -Xms128m
> -Xmx256m", :fork => false
>      test.resources
> {filter(project.path_to("src/main/ 
> resources")).into(test.resources.target).run}
>      test.compile.with(projects('api'), resources)

You need to either use java_args or fork=false -- not both.   
fork=false means that the test will run in the same JVM that buildr is  
using, meaning it doesn't start up a new one, meaning that java_args  
will be ignored.

Rhett

> = 
> = 
> = 
> ======================================================================
>
> It didn't work for as it didn't output that it is listening on a  
> port and
> waiting for an IDE to connect to. It just executed my test without  
> stopping.
> Any ideas/hints what's going on here?
>
> Thanks
> Babu
>
>
> On Tue, Nov 17, 2009 at 2:44 PM, Rhett Sutphin <rhett@detailedbalance.net 
> >wrote:
>
>> Hi Babu,
>>
>>
>> On Nov 17, 2009, at 3:30 PM, Babu Naidu wrote:
>>
>> Hi,
>>>
>>> I have a junit test that I would like to debug, however I am not  
>>> able to
>>> figure out how to pass java debug options to the JVM that runs  
>>> junit test
>>> or
>>> test task. For example, I would like to run the junit test with '- 
>>> Xdebug
>>> -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453' jvm  
>>> options
>>> and connect my IDE to it for further debugging. I tried setting  
>>> JAVA_OPTS
>>> variable, it didn't work, probably these options weren't  
>>> propagated to the
>>> JVM that ran my test as it didn't stop at a breakpoint in my test  
>>> class.
>>>
>>> Thanks
>>> Babu
>>>
>>
>> Check out this section of the docs:
>>
>> http://buildr.apache.org/languages.html#java
>>
>> You want to pass :java_args to test.using.  (Alternatively you  
>> could turn
>> off forking and use JAVA_OPTS, but I wouldn't recommend that.)
>>
>> Rhett
>>


Re: How to run a java test (Junit) in debug mode

Posted by Babu Naidu <pb...@gmail.com>.
Thanks.

I am on buildr 1.3.4 and Jruby 1.3.0 and I have  following code defined for
a project in build file.

      test.using :java_args => "-Xdebug
-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453 -Xms128m
-Xmx256m", :fork => false
      test.resources
{filter(project.path_to("src/main/resources")).into(test.resources.target).run}
      test.compile.with(projects('api'), resources)
=========================================================================

It didn't work for as it didn't output that it is listening on a port and
waiting for an IDE to connect to. It just executed my test without stopping.
Any ideas/hints what's going on here?

Thanks
Babu


On Tue, Nov 17, 2009 at 2:44 PM, Rhett Sutphin <rh...@detailedbalance.net>wrote:

> Hi Babu,
>
>
> On Nov 17, 2009, at 3:30 PM, Babu Naidu wrote:
>
>  Hi,
>>
>> I have a junit test that I would like to debug, however I am not able to
>> figure out how to pass java debug options to the JVM that runs junit test
>> or
>> test task. For example, I would like to run the junit test with '-Xdebug
>> -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453' jvm options
>> and connect my IDE to it for further debugging. I tried setting JAVA_OPTS
>> variable, it didn't work, probably these options weren't propagated to the
>> JVM that ran my test as it didn't stop at a breakpoint in my test class.
>>
>> Thanks
>> Babu
>>
>
> Check out this section of the docs:
>
> http://buildr.apache.org/languages.html#java
>
> You want to pass :java_args to test.using.  (Alternatively you could turn
> off forking and use JAVA_OPTS, but I wouldn't recommend that.)
>
> Rhett
>

Re: How to run a java test (Junit) in debug mode

Posted by Rhett Sutphin <rh...@detailedbalance.net>.
Hi Babu,

On Nov 17, 2009, at 3:30 PM, Babu Naidu wrote:

> Hi,
>
> I have a junit test that I would like to debug, however I am not  
> able to
> figure out how to pass java debug options to the JVM that runs junit  
> test or
> test task. For example, I would like to run the junit test with '- 
> Xdebug
> -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8453' jvm  
> options
> and connect my IDE to it for further debugging. I tried setting  
> JAVA_OPTS
> variable, it didn't work, probably these options weren't propagated  
> to the
> JVM that ran my test as it didn't stop at a breakpoint in my test  
> class.
>
> Thanks
> Babu

Check out this section of the docs:

http://buildr.apache.org/languages.html#java

You want to pass :java_args to test.using.  (Alternatively you could  
turn off forking and use JAVA_OPTS, but I wouldn't recommend that.)

Rhett