如何在java中设置默认主类? [英] how to set default main class in java?

查看:628
本文介绍了如何在java中设置默认主类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在同一个包中有2个类。这两个类都有主要方法。现在我想构建一个jar文件。我想构建2个使用不同主要功能作为默认主要文件的jar文件。

I have 2 classes within same package. Both classes have main method in them. Now I want to build a jar file. I want to build 2 jar files which use different main functions as default main.

例如

class A
{
  public static void main(String args[])
  {
    //do something
  }
}

class B
{
  public static void main(String args[])
  {
    //do something
  }
}

如何在NetBeans IDE中执行此操作?

How do I do it in NetBeans IDE?

我找到了答案。
你可以在netbeans中轻松完成:
1)右键单击项目>属性>运行>选择类frm和下拉列表。 netbeans如此简单。 Netbeans摇滚!

I found the answer. U can do it easily in netbeans: 1)right click on project >properties > run > select the class frm and drop down list. So simple in netbeans. Netbeans rocks!

推荐答案

在jar文件中你可以将它添加到你的manifest.mft

In the jar file you could just add this to your manifest.mft

Main-Class : A

然后jar文件可执行并调用正确的main。

The jar file would then be executable and would call the correct main.

关于如何在Netbeans中执行此操作,您可以查看:
在NetBeans中生成可执行jar

On how to do this in Netbeans you can look at this: Producing executable jar in NetBeans

这篇关于如何在java中设置默认主类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆