0

我需要一些帮助来将文件夹转换为可执行的 jar 文件。我想在我的应用程序中而不是从批处理文件中执行此操作。基本上我的桌面上有一个文件夹,里面已经有类文件,我只想把那个文件夹变成一个可执行的 jar 文件。

我已经尝试过这个:

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

不幸的是,这一切只是将文件夹重命名为我设置的名称,但不会更改文件类型。

对此的任何帮助将不胜感激。

4

2 回答 2

0

Making an executable JAR isn't as simple as renaming a folder. 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. You'll want to use the 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.

于 2013-09-29T03:20:40.020 回答
0

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

于 2013-09-29T03:14:52.050 回答