Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can i know if im running code within eclipse

 
Meir Yan
Ranch Hand
Posts: 599
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all

is there any way to make somekind of way to check in runtime ( in code )

if my code running within eclipse IDE? is there somekind of global variable i can query ?
 
Vanessa Astle
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you try adding a println statement to a particular method (if you want to see if its working or if the JVM gets that far). Then if you call that method later and run the code, you can see if that statement is being reached if the text that you placed in your println statement shows up on your console.

If you have alot of code to check and this seems like a rather tedious way to see if the code is running, you can always find out if there is a better way by looking it up in "The Java Developer's Guide to Eclipse" or any Eclipse resource.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50241
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no such thing as a global variable in Java, thank goodness.

But any IDE can have breakpoints set. You click somewhere to the left of the writing where the line numbers are. There are great differences between Eclipse and NetBeans here: in Eclipse they are blue and in NetBeans breakpoints are red.

Then rather than running the app, debug it. It will run normally until you get to the breakpoint, then you have 3 options:-
  • Step in (normal flow of control into a called method).
  • Step over (execute that method without inspecting it).
  • Step return (finish the present method without further inspection and return to wherever this method was called from).
  • At any point you can use the debug perspective to inspect the values of all variables in the entire application at that particular point.
    [ May 14, 2007: Message edited by: Campbell Ritchie ]
     
    Stan James
    (instanceof Sidekick)
    Ranch Hand
    Posts: 8791
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I rather thought I'd seen some way to do this before but I sure can't remember what it was. You could set a property in the Eclipse run dialog and test for it. Here's How To do it.
     
    Meir Yan
    Ranch Hand
    Posts: 599
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hello and thanks for the fast reply
    does any one knows how to set Global Value of a System Property in eclipse?
    so i could query it with System.getProperty?
     
    Christophe Verré
    Sheriff
    Posts: 14691
    16
    Eclipse IDE Ubuntu VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Run...
    Arguments/Vm arguments
    -Dmyprop=haha
    Run
     
    Meir Yan
    Ranch Hand
    Posts: 599
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hi i just want to be sure .. here is my startup cmd where i put the -D?

     
    Christophe Verré
    Sheriff
    Posts: 14691
    16
    Eclipse IDE Ubuntu VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    ?? You were asking how to set Global Value of a System Property in eclipse, not from the command line.
    So I've replied how to do it in Eclipse, through the "Run..." menu.
     
    Meir Yan
    Ranch Hand
    Posts: 599
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    hi and thanks for the fast reply

    you are right but there can be problem because in the way you suggested i will need to set this parameter for each class im executing
    and i like to make it more global , just set it once and use it all across my applications im developing in eclipse
    so maybe there is more general way to do this ?
     
    Christophe Verré
    Sheriff
    Posts: 14691
    16
    Eclipse IDE Ubuntu VI Editor
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sorry for the misunderstanding.
    Please try eclipse -vmargs -Dmyprop=hello
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic