| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 820 人关注过本帖
标题:看了好多方法 还是搞不明白 求助啊!!!
只看楼主 加入收藏
深藏依旧
Rank: 2
等 级:论坛游民
帖 子:45
专家分:93
注 册:2012-12-8
结帖率:100%
收藏
已结贴  问题点数:40 回复次数:8 
看了好多方法 还是搞不明白 求助啊!!!
把一个java程序和jar打包成可以在没有jdk的电脑上也能运行的.exe文件。 弄了一晚上,无奈总是不成功 求个有经验的帮个忙打包一下。跪求!下面是程序!

package
import java.util.Scanner;
public class Test {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println("*****欢迎进入客富翁系统*****");
        System.out.println("      1.注册        ");
        System.out.println("      2.登录        ");
        System.out.println("      3.抽奖        ");
        System.out.println("***************************");
        System.out.println("请输入");
        int e = (int) (Math.random() * 10000);
        int f = (int) (Math.random() * 10000);
        int c = (int) (Math.random() * 10000);
        int d = (int) (Math.random() * 10000);
        int g = (int) (Math.random() * 10000);
        Scanner input = new Scanner(System.in);
        int num = input.nextInt();
        switch (num) {
        case 1:
            System.out.println("【奖客富翁系统>注册】");
            System.out.println("继续吗?(Y/N)");
            String a = input.next();
            if (a.equals("Y")) {
                System.out.println("请输入个人信息:");

                System.out.print("用户名:");
                String name = input.next();

                System.out.print("密码:");
                String pwd = input.next();
                System.out.println("注册成功,请记好你的会员卡号");
                System.out.println("用户名      密码      会员卡号");

                System.out.print(name + "      " + pwd + "      ");
                int rand = (int) (Math.random() * 10000);
                System.out.println(rand);
                System.out.println("继续吗?(Y/N)");
                String b = input.next();
                if (b.equals("Y")) {
                    System.out.println("*****欢迎进入客富翁系统*****");
                    System.out.println("      1.注册        ");
                    System.out.println("      2.登录        ");
                    System.out.println("      3.抽奖        ");
                    System.out.println("***************************");
                    System.out.println("请输入");
                    int num1 = input.nextInt();
                    switch (num1) {
                    case 1:System.out.print("请输入用户名");
                    String name5 = input.next();
                    System.out.print("请输入密码");
                    String pwd5 = input.next();
                        if(name.equals(name5)){
                            System.out.println("用户已被注册");
                        
                    }
                        
                           
                    break;
                    case 2:
                        System.out.print("请输入用户名");
                        String name1 = input.next();
                        System.out.print("请输入密码");
                        String pwd1 = input.next();

                        if (pwd.equals(pwd1) && name.equals(name1)) {
                            System.out.println("欢迎你:" + name);
                            System.out.println("*****欢迎进入客富翁系统*****");
                            System.out.println("      1.注册        ");
                            System.out.println("      2.登录        ");
                            System.out.println("      3.抽奖        ");
                            System.out.println("***************************");
                            System.out.println("请输入");

                            int num2 = input.nextInt();
                            switch (num2) {
                            case 3:
                                System.out.println("请输入会员卡号");
                                int vip = input.nextInt();
                                if (vip == e) {
                                    System.out.println("中奖了");

                                } else if (vip == f) {
                                    System.out.println("中奖了");

                                } else if (vip == c) {
                                    System.out.println("中奖了");

                                } else if (vip == d) {
                                    System.out.println("中奖了");

                                } else if (vip == g) {
                                    System.out.println("中奖了");

                                } else
                                    System.out.println("非常遗憾没中奖");
                                System.out.println("中奖号码为" + " " + g + " " + c
                                        + " " + d + " " + e + " " + f);

                                break;

                            default:
                                break;
                            }

                        }

                        else {
                            System.out.println("用户名或密码错误请重新输入(你还可以输入两次)");

                            System.out.print("请输入用户名");
                            String name2 = input.next();
                            System.out.print("请输入密码");
                            String pwd2 = input.next();

                            if (pwd.equals(pwd2) && name.equals(name2)) {
                                System.out.println("欢迎你:" + name);
                                System.out.println("*****欢迎进入客富翁系统*****");
                                System.out.println("      1.注册        ");
                                System.out.println("      2.登录        ");
                                System.out.println("      3.抽奖        ");
                                System.out
                                        .println("***************************");
                                System.out.println("请输入");
                                int num3 = input.nextInt();
                                switch (num3) {
                                case 3:
                                    System.out.println("请输入会员卡号");
                                    int vip = input.nextInt();
                                    if (vip == e) {
                                        System.out.println("中奖了");

                                    } else if (vip == f) {
                                        System.out.println("中奖了");

                                    } else if (vip == c) {
                                        System.out.println("中奖了");

                                    } else if (vip == d) {
                                        System.out.println("中奖了");

                                    } else if (vip == g) {
                                        System.out.println("中奖了");

                                    } else
                                        System.out.println("非常遗憾没中奖");
                                    System.out.println("中奖号码为" + " " + g + " "
                                            + c + " " + d + " " + e + " " + f);

                                    break;

                                default:
                                    break;
                                }

                            } else {
                                System.out.println("用户名或密码错误请重新输入(你还可以输入两次)");

                                System.out.print("请输入用户名");
                                String name3 = input.next();
                                System.out.print("请输入密码");
                                String pwd3 = input.next();

                                if (pwd.equals(pwd3) && name.equals(name3)) {
                                    System.out.println("欢迎你:" + name);
                                    System.out.println("*****欢迎进入客富翁系统*****");
                                    System.out.println("      1.注册        ");
                                    System.out.println("      2.登录        ");
                                    System.out.println("      3.抽奖        ");
                                    System.out
                                            .println("***************************");
                                    System.out.println("请输入");
                                    int num4 = input.nextInt();
                                    switch (num4) {
                                    case 3:
                                        System.out.println("请输入会员卡号");
                                        int vip = input.nextInt();
                                        if (vip == e) {
                                            System.out.println("中奖了");

                                        } else if (vip == f) {
                                            System.out.println("中奖了");

                                        } else if (vip == c) {
                                            System.out.println("中奖了");

                                        } else if (vip == d) {
                                            System.out.println("中奖了");

                                        } else if (vip == g) {
                                            System.out.println("中奖了");

                                        } else
                                            System.out.println("非常遗憾没中奖");
                                        System.out.println("中奖号码为" + " " + g
                                                + " " + c + " " + d + " " + e
                                                + " " + f);

                                        break;

                                    default:
                                        break;
                                    }

                                } else
                                    System.out
                                            .println("用户名或密码错误请重新输入(你还可以输入两次)");
                            }
                        }

                        break;

                    default:
                        break;
                    }
                } else if (b.equals("N")) {
                    System.out.println("系统退出,谢谢使用!");
                } else
                    System.out.println("系统退出,谢谢使用!");

            } else if (a.equals("N")) {
                System.out.println("系统退出,谢谢使用!");
            } else
                System.out.println("系统退出,谢谢使用!");

            break;
        case 2:
            System.out.println("");
            break;
        case 3:
            System.out.println("");
            break;

        default:
            System.out.println("您的输入有误");
            break;
        }
    }
}
一个抽奖的系统,用java做的。
搜索更多相关主题的帖子: package java程序 import public method 
2014-05-10 21:52
深藏依旧
Rank: 2
等 级:论坛游民
帖 子:45
专家分:93
注 册:2012-12-8
收藏
得分:0 
求解答啊

厚积薄发
2014-05-10 21:58
韶志
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:斗气大陆
等 级:贵宾
威 望:44
帖 子:2223
专家分:13592
注 册:2013-3-22
收藏
得分:0 
生成EXE?

三十年河东,三十年河西,莫欺少年穷!
2014-05-11 10:59
深藏依旧
Rank: 2
等 级:论坛游民
帖 子:45
专家分:93
注 册:2012-12-8
收藏
得分:0 
对啊 就是把java程序和虚拟机一起生成一个可执行的.exe文件  试了好多回都不行

厚积薄发
2014-05-11 12:12
星112
Rank: 5Rank: 5
来 自:山西朔州
等 级:职业侠客
威 望:2
帖 子:94
专家分:342
注 册:2012-6-22
收藏
得分:0 
首先确定你程序没有问题吧,你可以用exe4j_pj这个软件处理一下,这个是我用过的,基本上没有问题,处理生成没有安装jdk的电脑单机文件
2014-05-11 12:53
日知己所无
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:38
帖 子:427
专家分:2071
注 册:2014-3-22
收藏
得分:40 
打包好了
Test.zip (13.46 KB)


执行结果
图片附件: 游客没有浏览图片的权限,请 登录注册


打包时使用软件launch4j 3.4
下载地址:http://www.
2014-05-11 13:16
日知己所无
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:38
帖 子:427
专家分:2071
注 册:2014-3-22
收藏
得分:0 
基本步骤:
■1)用eclipse生成可执行的jar文件
1-010)用eclipse新建一个Project,比如:jar2exe
1-020)创建
1-030)创建Test类,注意:要在新建类的窗口上把“public static void main(String[] args)(V)”勾选上
1-040)在eclipse中按下Ctrl+F11,在eclipse的控制台中得能看到“欢迎进入客富翁系统”这样的字样才能进行后继步骤
1-050)在eclipse中用右键单击Package Explorer导航窗口里的包的图标,选择Export菜单项,注意:缺省的选项是“JAR文件”,需要自己手动选择“下面的可执行JAR文件”
1-060)在“可执行JAR文件 Export”窗口中,“启动构成”栏需要自己手动设置成“Test - jar2exe”,其中Test是包含main方法的入口主类的名字,jar2exe是1-010步骤生成的Project名称;如果这里显示不出来主类名称的话,估计是1-030的步骤没做好的原因,可以重新试一下1-030的步骤。
1-070)指定输出路径,比如C:\java\launch4j\Test.jar,按下“完成”按钮

1-080)在控制台中执行C:\java\launch4j>java -jar Test.jar
得在Windows的控制台中能看到“欢迎进入客富翁系统”这样的字样才能进行后继步骤

1-090)解压Test.jar文件,查看下面这个文件
C:\java\launch4j\Test\META-INF\MANIFEST.MF

至少得包含类似下面这样的信息
Manifest-Version: 1.0
Main-Class:

1-100)如果1-090不正确,可以考虑手动追加上,再用压缩软件压缩成zip文件,把zip文件改名为jar即可
注意:压缩时要在C:\java\launch4j\Test这层目录里操作,全选所有目录和文件后压缩,否则会多出一层变成Test\Test这样的结构

■2)用launch4j生成可执行的exe文件
2-010)去官网下载最新版本的launch4j,发帖时最新版为3.4,最好下载exe版,直接Setup比较省事儿
http://

2-020)在launch4j需要设定的东东
Basic标签:
  Outfile选项:C:\java\launch4j\Test.exe
  Jar选项:C:\java\launch4j\Test.jar

Classpath标签:
  MainClass选项:

Header标签:
  HeaderType选项:console【这个比较重要,否则执行Test.exe时,什么都不输出就结束了】

JRE标签:
  MinVersion选项:1.5.0【可以根据具体情况更改设置,但是格式应该是左侧这样的】

2-030)设置好后,压下小齿轮图标,执行“Build wrapper”命令

2-040)在控制台中输入C:\java\launch4j>Test.exe就OK了

补充说明:
1)能否在完全没有安装JDK和JRE的机器上运行,需要测试一下,理论上来讲没有问题
2)上面菜单上的信息仅供参考,有的时候为了表述方便,混用了中英文,具体操作可以以自己电脑上的提示信息为主
3)哪个步骤发生问题了,请提供截屏等足够的信息,这样方便别人帮助你分析问题

最后,由于步骤实在多,又有很多容易出错的小陷阱,祝你Good Luck!
2014-05-11 13:53
日知己所无
Rank: 11Rank: 11Rank: 11Rank: 11
等 级:贵宾
威 望:38
帖 子:427
专家分:2071
注 册:2014-3-22
收藏
得分:0 
launch4j是免费开源的工具,一直在持续更新着
生成的EXE从WIN98一直支持到WIN8,推荐使用
2014-05-11 14:08
深藏依旧
Rank: 2
等 级:论坛游民
帖 子:45
专家分:93
注 册:2012-12-8
收藏
得分:0 
太感谢了,真是不知道该说什么了!谢谢!!我按你的步骤再试一试!

厚积薄发
2014-05-11 17:15
快速回复:看了好多方法 还是搞不明白 求助啊!!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.057382 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved