开发者

Code jumps out of a jar and runs? What is causing this?

开发者 https://www.devze.com 2023-01-01 13:41 出处:网络
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:

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 ht开发者_开发技巧tp://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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号