[英]Java GUI runs executable + Jar Packaging
I am developing a GUI using swing that runs an executable. 我正在使用运行可执行文件的swing开发GUI。 Currently the executable is being used via
Runtime.getRuntime().exec()
. 当前,可执行文件通过
Runtime.getRuntime().exec()
。
I have both the executable and the source code. 我既有可执行文件,也有源代码。 If I compile my GUI into a jar the executable will not be included into as it currently stands, correct?
如果我将GUI编译到jar中,那么可执行文件将不包含在当前状态下,对吗?
I would like the whole thing to run as a single file, is it better then to use the source code or can I package it all as one jar when I'm done some how? 我希望整个事情都可以作为一个文件运行,是比使用源代码更好,还是在完成某些工作后将其打包为一个jar?
Though I'm writing all the code by hand I do have WindowBuilder for eclipse, I haven't really explored it thoroughly, is there anything in there that might help? 尽管我正在手工编写所有代码,但我确实拥有用于eclipse的WindowBuilder,但是我还没有真正对其进行全面的探索,其中是否有任何可能的帮助?
EDIT: Sorry, to clarify: The GUI I want to build uses an executable called src2srcml to take a source file (C, C++, Java) and convert it to an XML File. 编辑:对不起,澄清一下:我要构建的GUI使用名为src2srcml的可执行文件来获取源文件(C,C ++,Java)并将其转换为XML文件。 src2srcml is a separate executable I got from this website: http://www.sdml.info/projects/srcml/
src2srcml是我从以下网站获得的独立可执行文件: http ://www.sdml.info/projects/srcml/
I want to embed this executable into my GUI so that when I compile my GUI into a JAR it contains src2srcml inside it so that I don't need to send a client both my GUI and src2srcml separately. 我想将此可执行文件嵌入到我的GUI中,以便在将我的GUI编译为JAR时,它在其中包含src2srcml,这样就无需分别发送GUI和src2srcml客户端。
If you include the executable within the Jar, the executable will not be runnable by the OS. 如果您将可执行文件包含在Jar中,则该操作系统将无法运行该可执行文件。
With that in mind, you have a number of choices... 考虑到这一点,您有很多选择...
Design a build process that compiles and packages the jar file, takes that and the executable and copies it into an appropriate directory structure for distribution...possible even building installers... 设计一个构建过程来编译和打包jar文件,获取该jar文件和可执行文件,然后将其复制到适当的目录结构中进行分发...甚至可以构建安装程序...
This will mean that you can still access the executable at runtime by using a relative path 这意味着您仍然可以在运行时通过使用相对路径来访问可执行文件
This does mean you will have at least two files you will need to distribute, but the over all process is relatively painless... 这确实意味着您将至少需要分发两个文件,但是整个过程相对来说并不麻烦。
Include the executable within the jar file. 将可执行文件包含在jar文件中。 At runtime, you would need to extract the executable to the filesystem and execute it.
在运行时,您需要将可执行文件提取到文件系统并执行。
This means that you will have at least one file you will need to distribute, but it complicates the development process as you will need to find the resources (executable) at run time and extract it to some location before you can execute it 这意味着您将至少需要分发一个文件,但这会使开发过程变得复杂,因为您需要在运行时查找资源(可执行文件)并将其提取到某个位置,然后才能执行它。
Just build an installer for your application. 只需为您的应用程序构建安装程序即可。 Something like like izPack for example, or what ever installer you want to use.
例如izPack之类的东西,或者您想使用的任何安装程序。
This means that you can distribute a single file to the client, but when installed, it will unpack all the files into the installation location and you won't need to care... 这意味着您可以将单个文件分发给客户端,但是在安装后,它将把所有文件解压缩到安装位置,您无需担心...
我不确定我是否理解您的问题,但是如果您想将应用程序导出到jar文件中,并且希望它包含所有依赖关系,请查看以下SO问题: 如何使用Eclipse中包含的外部库创建jar ?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.