简体   繁体   English

将文件夹转换为Java中的可执行jar文件

[英]Turning a folder into an executable jar file in Java

I need some help with turning a folder into an executable jar file. 我需要将文件夹转换为可执行jar文件的一些帮助。 I want to do this in my application not from a batch file. 我想在我的应用程序中而不是从批处理文件中执行此操作。 Basically i have a folder on my desktop with class files already in it, all i want is to turn that folder into an executable jar file. 基本上,我的桌面上已经有一个包含类文件的文件夹,我所要做的就是将该文件夹转换为可执行的jar文件。

I have already tried this: 我已经尝试过了:

    File file = new File(System.getProperty("user.home") + "/Desktop/myfolderwithclasses");
    File file2 = new File(System.getProperty("user.home") + "/Desktop/myfolderwithclasses.jar");
    file.renameTo(file2);

Unfortunately all this does is rename the folder to what i set but it doesn't change the file type. 不幸的是,所有这些操作只是将文件夹重命名为我设置的名称,但它不会更改文件类型。

Any help with this would be greatly appreciated. 任何帮助,将不胜感激。

您可以使用eclipse并导出可运行的jar。

Making an executable JAR isn't as simple as renaming a folder. 制作可执行的JAR并不像重命名文件夹那样简单。 You can use IDE functionality, as has been mentioned, but a more portable solution is to use something like Apache Ant, which is actually supported in a lot of the IDEs. 如前所述,您可以使用IDE功能,但是更可移植的解决方案是使用Apache Ant之类的东西,许多IDE实际上都支持该功能。 You'll want to use the JAR Task . 您将要使用JAR Task If you just have your own classes to package, and no complicated library structure, the examples at the bottom of the page should suffice. 如果您只需要打包自己的类,而没有复杂的库结构,则页面底部的示例就足够了。 Here's a Hello World tutorial for Ant to help you set up your build file. 这是Ant的Hello World教程 ,可帮助您设置构建文件。

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

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