如何在java中创建exe文件 [英] How to create an exe file in java

查看:130
本文介绍了如何在java中创建exe文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想为我的java应用程序创建一个exe文件。

Hi I want to create an exe file for my java app.

我尝试了一些第三方软件JEXECreator,成功创建了exe文件,并且其工作正常我的系统,当我尝试使用另一台机器时,它不起作用。我收到以下错误

I tried with some third party softwares JEXECreator, successfully created the exe file and its working fine in my system, when I tried with another machine, it’s not working. I got the following error

    * The error occurred while running the application. The exit code is 0x10000223.
    * Contact the vendor of the application for troubleshooting.

    java.lang.ClassNotFoundException: com.sample.SampleMain
         at java.net.URLClassLoader$1.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClass(Unknown Source)
         at java.lang.ClassLoader.loadClassInternal(Unknown Source)
         at java.lang.Class.forName0(Native Method)
         at java.lang.Class.forName(Unknown Source)
         at com.ucware.JEXEClassLoader.run(Unknown Source)
         at com.ucware.JEXEClassLoader.main(Unknown Source)
    **************************************

我知道我设置的类路径有问题。

I know there is something wrong with the classpath which I set.

其实我想要创建exe文件我自己没有使用任何第三方软件。

Actually I want to create the exe file myself without using any third party software.

我在很多网站找到了步骤

I found the steps in lot of sites

创建了清单文件名为Sample.mft,内容如下:

Created the manifest file named Sample.mft with following contents

         Manifest-Version: 1.0
         Main-Class: 
         Class-path:

在此我有些疑惑,


  1. 如何添加Main-Class,包括完整包名(com.sample.SampleMain)或类名(SampleMain)或扩展名(SampleMain。 class)

  1. How the Main-Class should be added, with the full package name (com.sample.SampleMain) or the class name alone (SampleMain) or with the extension (SampleMain.class)

如何添加类路径,我的项目中有4个java类和2个jar。如何在类路径中添加所有这些,我是否需要在类路径中添加java jdk。

How the class-path should be added, I have 4 java classes and 2 jars in my project. How to add all these in the class path, and do I need to add the java jdk in classpath.

应该保存清单文件的位置

Where the manifest file should be saved

清单文件扩展名应该是什么(mf或mft)

What should be the manifest file extension (mf or mft)

在命令提示符下目录我应该创建exe文件(从我的项目文件夹或src文件夹或包含所有java类的文件夹)

In command prompt from which directory I should create the exe file (from my project folder or src folder or the folder which contains all the java classes)

应该使用什么语法在命令提示符下创建jar

What’s the syntax should be used while creating jar in command prompt

(jar cmf Sample.mf Sample.jar Sample1.class Sample2.class Sample3.class像这样的Sample4.class jar1.jar jar2.jar)或(jar cvfm Sample.jar sample.mf * .class)

(jar cmf Sample.mf Sample.jar Sample1.class Sample2.class Sample3.class Sample4.class jar1.jar jar2.jar) like this or (jar cvfm Sample.jar sample.mf *.class)

当我做了这样的事情时我得到了一个jar而不是exe文件,当我在命令提示符下使用java -jar sample.jar运行jar时,我得到类找不到异常。

When I did something like this I am getting a jar instead of exe file, When I run the jar in command prompt using "java -jar sample.jar" then I am getting class not found exception".

实际上如何创建一个exe文件而不是jar文件,这意味着只需双击即可那个exe文件,应该在任何机器上运行我的应用程序。

Actually how to create an exe file instead of jar file, that means just by double clicking that exe file, should run my app in any machine.

任何人都可以帮我这样做吗?

Can anyone help me to do this?

在此先感谢。

推荐答案

我使用Eclipse IDE下的Ant工具与InnoSetup和Launch4J一起创建EXE及其安装程序它还管理类路径......

I use the Ant tool under Eclipse IDE to work with InnoSetup and Launch4J to create the EXE and its installer which it also manages the classpath...

指南?您可以参考:

http: //www.eteks.com/tips/tipCreationExe.html (法语)

这篇关于如何在java中创建exe文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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