aspose file tools*
The moose likes Beginning Java and the fly likes how can i know if im running code within eclipse Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how can i know if im running code within eclipse " Watch "how can i know if im running code within eclipse " New topic
Author

how can i know if im running code within eclipse

Meir Yan
Ranch Hand

Joined: Apr 27, 2006
Posts: 597
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

Joined: May 08, 2007
Posts: 37
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

Joined: Oct 13, 2005
Posts: 39436
    
  28
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

    Joined: Jan 29, 2003
    Posts: 8791
    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.


    A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
    Meir Yan
    Ranch Hand

    Joined: Apr 27, 2006
    Posts: 597
    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

    Joined: Nov 24, 2005
    Posts: 14688
        
      16

    Run...
    Arguments/Vm arguments
    -Dmyprop=haha
    Run


    [My Blog]
    All roads lead to JavaRanch
    Meir Yan
    Ranch Hand

    Joined: Apr 27, 2006
    Posts: 597
    hi i just want to be sure .. here is my startup cmd where i put the -D?

    Christophe Verré
    Sheriff

    Joined: Nov 24, 2005
    Posts: 14688
        
      16

    ?? 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

    Joined: Apr 27, 2006
    Posts: 597
    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

    Joined: Nov 24, 2005
    Posts: 14688
        
      16

    Sorry for the misunderstanding.
    Please try eclipse -vmargs -Dmyprop=hello
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: how can i know if im running code within eclipse