5

I am trying to get a sample program working with JUNG, a graphing tool in Java. I downloaded and referenced all the .jar files in eclipse so my project hierarchy looks like this: alt text http://img638.imageshack.us/img638/6787/hierarchy.png

In Test.java I have the following code:

public class Test {

static public void main() {
    System.out.print("Hello");
}}

For some reason though when I try to run it as a Java Application by right clicking on Jung test in the project hierarchy I am presented with a bunch of classes. My Test.java isn't on the list so if I just leave it as ** and press ok it starts running a program that is dynamically adding nodes and vertexes to a graph. I can't seem to figure out what code its actually executing. I know java but stuff like this with the jar files seems to be getting lost on me. Any ideas?

Thanks

Mike
  • 1,481
  • 6
  • 17
  • 22
  • 2
    Post a screenshot of what is being presented when you hit run, sounds like you need to set up Eclipse to point to the right class. – Freiheit May 25 '10 at 21:17
  • 4
    Something that tries to jump our of a jar and run away? What you have is a bug...:-) – DJClayworth May 25 '10 at 21:22
  • 5
    Ah must be the gingerbread class :) – crowne May 25 '10 at 21:23
  • http://img175.imageshack.us/img175/4788/maintypes.png That is a screenshot of what is presented. IT says searching for main types then presents me with this screen. – Mike May 26 '10 at 15:07

1 Answers1

5

My guess based on the symptoms that you have posted is that your startup command in Eclipse is pointed to the wrong main class. First off, your main method needs to look like this:

public static void main(String[] args) {
    //stuff here
}

Then you can right-click on the file (either in the editor or in the explorer view) and choose "Run As -> Java Application" from the context menu. This will create a run configuration for that main file.

I think the real problem is that you don't have the main method defined correctly - that will allow your class to show up as a possible class to run from.

aperkins
  • 12,914
  • 4
  • 29
  • 34
  • 1
    I should note that, depending on your version of Eclipse, the context menu will often tell you if your main method is constructed wrong, as it will not even let you attempt to do the "Run As -> Java Application" option unless it has a main method. – aperkins May 25 '10 at 21:47
  • You were exactly right on the main method. I am a C++ programmer so I got a little lost in the translation. Thanks for the help. – Mike May 26 '10 at 15:09