代码从 jar 中跳出来并运行?是什么原因造成的?

发布于 2024-09-03 07:15:55 字数 603 浏览 2 评论 0原文

我正在尝试使用 JUNG(Java 中的图形工具)使用示例程序。我下载并引用了 eclipse 中的所有 .jar 文件,因此我的项目层次结构如下所示: 替代文本 http://img638.imageshack.us/img638/6787/hierarchy.png

测试中。 java 我有以下代码:

public class Test {

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

出于某种原因,尽管当我尝试通过右键单击项目层次结构中的 Jung test 将其作为 Java 应用程序运行时,我会看到一堆类。我的 Test.java 不在列表中,因此如果我将其保留为 ** 并按“确定”,它就会开始运行一个向图形动态添加节点和顶点的程序。我似乎无法弄清楚它实际执行的代码是什么。我了解 java,但像这样的 jar 文件似乎让我迷失了。有什么想法吗?

谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

时光是把杀猪刀 2024-09-10 07:15:55

根据您发布的症状,我的猜测是您在 Eclipse 中的启动命令指向了错误的主类。首先,您的 main 方法需要如下所示:

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

然后您可以右键单击该文件(在编辑器或资源管理器视图中)并从上下文菜单中选择“运行方式 -> Java 应用程序”。这将为该主文件创建一个运行配置。

我认为真正的问题是您没有正确定义 main 方法 - 这将允许您的类显示为可能的运行类。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文