Java Eclipse可执行jar文件 [英] Java Eclipse executable jar file

查看:179
本文介绍了Java Eclipse可执行jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是eclipse + Java的新手。我正在尝试使用eclipse
导出选项创建可执行jar文件。它工作得很好。但在我的项目中,我有近10个包(我自己的)和4个主要类。我想创建一个可执行jar文件,可以执行4个主类中的任何主类。

I am new to eclipse + Java. I am trying to create executable jar file with eclipse export option. It works very well. But in my project, I have almost 10 packages (my own) and 4 main classes. I want to create a executable jar file that can execute any of main class from 4 main classes.

例如:双击写类名并运行该类

For example: Double click write class name and run that class

推荐答案

只是一个快速的例子,说明如何处理命令行选项以启动不同的东西,我会把它放到@ serplat的回答中,但我不能格式化它。

Just a quick example of how to deal with command line options to launch different things, I would have put it into a reply to @serplat's answer but then I can't format it.

public static void main(String[] args)
{
    if(args.length == 0) {
        // Do default here--no options specified
    } else if(args.length > 2) {
        // Complain that there are too many args, or implement multi-args
    } else // known just one arg
       if(args[1].equals("option1") {
           // call the main of your first app
       } else if(args[1].equals("option2") {
           // start your second app
      ...
   }
}

有更好的方法来处理命令行的东西,但这是可以理解的,应该做你需要的。后来你可能会考虑更灵活的事情。

There are much better ways to handle command line stuff, but this is understandable and should do what you need. Later you might look into something more flexible.

这篇关于Java Eclipse可执行jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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