采取eclipse java项目并将其打包到jar中?

时间:2023-01-13 12:59:17

Right now i've written a simple SWT application using eclipse, and I want to pack it into an executable .jar file so I can give it out to friends and such. But I have the following problems: -Right now i'm reading files by using their filename in the program, and putting them in the root folder of the eclipse project. That works fine for running in eclipse, but when I export to jar they're not in the jar. Is there a way to put them in the jar and access them in the code? -I also need the SWT .jar dependencies or whatever its called(the files you need for SWT).

现在我用eclipse编写了一个简单的SWT应用程序,我想把它打包成一个可执行的.jar文件,这样我就可以把它发给朋友等了。但是我有以下问题: - 现在我正在通过在程序中使用文件名来读取文件,并将它们放在eclipse项目的根文件夹中。这适用于在eclipse中运行,但是当我导出到jar时,它们不在jar中。有没有办法把它们放在jar中并在代码中访问它们? - 我还需要SWT .jar依赖项或其调用的任何内容(SWT所需的文件)。

Does anyone know how to do this?

有谁知道如何做到这一点?

2 个解决方案

#1


0  

Take a look at ClassLoader.getResourceAsStream() API.

看看ClassLoader.getResourceAsStream()API。

#2


0  

All you need to do is include these files in the with the source code of your project, then to have access to then have a look at this link

您需要做的就是将这些文件包含在项目的源代码中,然后访问,然后查看此链接

#1


0  

Take a look at ClassLoader.getResourceAsStream() API.

看看ClassLoader.getResourceAsStream()API。

#2


0  

All you need to do is include these files in the with the source code of your project, then to have access to then have a look at this link

您需要做的就是将这些文件包含在项目的源代码中,然后访问,然后查看此链接