简体   繁体   English

我的launch4j .exe文件无法像我的java文件那样工作。 我想念什么吗?

[英]My .exe file from launch4j does not work like my java file. Am I missing something?

As someone new to java and bundling programs with code, I was able to successfully get the proper output running a simple new HelloWorld java file. 作为Java新手并使用代码捆绑程序,我能够运行一个简单的新HelloWorld Java文件成功获得正确的输出。 So I believe there are no issues with the java file in terms of compiling it to a class file or running it afterwards, and that I have all the files needed in the java kit to create an executable file. 因此,我认为将Java文件编译为类文件或之后运行该文件没有问题,并且我拥有Java套件中创建可执行文件所需的所有文件。 However, I am not sure if I am using launch4j properly to get the .exe, either with setting up the .jar or through the process from making a proper .xml file. 但是,我不确定是否通过设置.jar或通过制作适当的.xml文件的过程正确使用launch4j来获取.exe。

The code below shows what I get when I try to put everything into the .jar file, but I guess the output is an error because a new .jar file isn't produced unless I take out the "m" from the "cvfm" in the jar command. 下面的代码显示了当我尝试将所有内容放入.jar文件时得到的结果,但是我猜输出是错误的,因为除非我从“ cvfm”中取出“ m”,否则不会生成新的.jar文件在jar命令中。 The code does show something about the manifest being added regardless when doing so, yet I still do not get a proper application. 该代码确实显示了有关添加清单的某些信息,尽管这样做仍然没有,但是我仍然没有获得适当的应用程序。 After getting the correct output without launch4j, I stopped recreating the .java and .class files and just focused on the .xml when recreating the .jar file achieved no difference. 在没有launch4j的情况下获得正确的输出后,我停止了重新创建.java和.class文件,而只是在重新创建.jar文件时没有任何区别的时候专注于.xml。 I have tried in launch4j leaving the environment variables blank in the JRE tab or just included the same path of the system variables that the java file worked with correctly in the command prompt, and I have also switched the check of GUI to console in the header tab. 我已经在launch4j中尝试过,将环境变量在JRE选项卡中留为空白,或者仅在命令提示符下包含与Java文件正确使用的系统变量相同的路径,并且还将GUI的检查切换为标头中的console标签。 Research has also told me to look up a manifest.mf file, to which I don't think I have that precise file in the JDK, but may have found something similar in the kit (at least when looking in typical areas like the bin folder). 研究还告诉我要查找manifest.mf文件,我认为JDK中没有该文件,但可能在工具包中找到了类似的文件(至少在查找诸如bin等典型区域时)夹)。

C:\JavaTest>jar cvfm HelloWorld.jar HelloWorld.class
java.io.IOException: invalid header field
        at java.util.jar.Attributes.read(Attributes.java:406)
        at java.util.jar.Manifest.read(Manifest.java:234)
        at java.util.jar.Manifest.<init>(Manifest.java:81)
        at java.util.jar.Manifest.<init>(Manifest.java:73)
        at sun.tools.jar.Main.run(Main.java:176)
        at sun.tools.jar.Main.main(Main.java:1288)

C:\JavaTest>jar cvf HelloWorld.jar HelloWorld.class
added manifest
adding: HelloWorld.class(in = 426) (out= 289)(deflated 32%)

I always get a warning about signing when testing the wrapper, but I don't think that has been an issue like an actual error. 在测试包装器时,我总是会收到有关签名的警告,但我认为这并不是像实际错误那样的问题。 Due to the nature of the numerous combinations, it is hard to keep track of what caused the differences in issues, but it seems that now leaving the JRE tab blank except for having a min JRE version yields the error "no main manifest attribute" right from the wrapper test in launch4j. 由于众多组合的性质,很难跟踪导致问题差异的原因,但是似乎现在将JRE选项卡留空了,除了拥有最小的JRE版本以外,还会产生错误“无主清单属性”来自launch4j中的包装器测试。 Having the very end of the system variable path included in the environment variable field does the same thing. 将环境变量字段中包含的系统变量路径的末尾做同样的事情。 Before trying to recreate the .jar, switching the header to console would create a .exe without errors, but either opening the application would either do nothing or put the same "no main manifest attribute" output in the command prompt. 在尝试重新创建.jar之前,将标头切换到控制台将创建一个没有错误的.exe,但是打开应用程序将不执行任何操作,或者在命令提示符下输出相同的“ no main manifest attribute”。 Now, I can't even use launch4j to test wrappers that have the header on console even when building them produces no errors (yet the same error happens when opening the .exe). 现在,我什至不能使用launch4j来测试在控制台上具有标头的包装器,即使在构建它们时也不会产生错误(但是打开.exe时也会发生相同的错误)。 I am just trying to get the .exe produced from launch4j to provide the same output in the command prompt that I get when typing "java HelloWorld" there. 我只是想让launch4j生成.exe,以便在命令提示符下提供与在其中键入“ java HelloWorld”时得到的输出相同的输出。

If I am indeed creating the .jar properly and working with launch4j properly, did I just miss the unlisted step of needing some sort of manifest file to work with launch4j? 如果确实要正确创建.jar并正确使用launch4j,我是否只是错过了需要某种清单文件才能与launch4j一起使用的未列出步骤? If so, how would I make sure I got it properly? 如果是这样,我如何确保我正确地获得了它? Would it be seen in a bin folder or completely separate from the JDK? 它会显示在bin文件夹中还是与JDK完全分开? Would I need to move it to my JavaTest folder where the java/class/jar/exe files are? 我需要将其移动到java / class / jar / exe文件所在的JavaTest文件夹中吗? Any help is truly appreciated. 任何帮助,我们都感激不尽。

The 'm' in jar cvfm stands for manifest, and implies that you will be providing a file as argument which is the manifest. jar cvfm的'm'代表清单,表示您将提供一个文件作为清单文件。 The f stands for: You will specify the file name. f代表:您将指定文件名。

So, HelloWorld.jar is the argument to the f, and HelloWorld.class is the argument to the m. 因此, HelloWorld.jar是f的参数,而HelloWorld.class是m的参数。 Your class file, obviously, isn't a valid manifest file, hence why the error occurs. 您的类文件显然不是有效的清单文件,因此为什么会发生错误。

Generally, use a build tool to make jars, such as maven or gradle. 通常,使用构建工具来制作罐子,例如maven或gradle。 You need a manifest in order to have a Main-Class attribute, and you need a Main-Class attribute to create a runnable jar, and you need a runnable jar to launch4j-ify it. 您需要一个清单以拥有Main-Class属性,并且需要Main-Class属性来创建可运行的jar,并且需要可运行的jar来启动它。

Make a file named MANIFEST.MF. 制作一个名为MANIFEST.MF的文件。 Create it with a plain text editor. 用纯文本编辑器创建它。 It should contain: 它应包含:

Main-Class: com.foo.thisIsAPackage.YourMainClass

and nothing else. 没别的。

Then: 然后:

jar cvfm HelloWorld.jar MANIFEST.MF YourMainClass.class

note that I'm pretty sure you MUST have a package or this is not going to work. 请注意,我很确定您必须有一个包装,否则将无法使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM