Java GUI runs executable + Jar Packaging - java

I am developing a GUI using swing that runs an executable. Currently the executable is being used via 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?
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?
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?
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. src2srcml is a separate executable I got from this website: 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.

If you include the executable within the Jar, the executable will not be runnable by the OS.
With that in mind, you have a number of choices...
You Could...
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...
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...
You Could...
Include the executable within the jar file. 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
You Could...
Just build an installer for your application. Something like like izPack for example, or what ever installer you want to use.
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...

I'm not sure if I understood your question, but if you want to export you application into jar file and you want it to include all dependecies just have a look at this SO question: How to create a jar with external libraries included in Eclipse?

Related

Compile python files + all dependecies + intepreter into one java\.net (dll or exe) file?

I have a couple of python files with some dependencies on third-party libraries, like pyaudio. So is there a way to compile everything including python intepreter itself into one .jar\dll file to use them in java\android or xamarin\ .net core, without actual installing python + doing pip install every time?
Also as an option - compile into c\c++?
You can use PyInstaller to create an executable.
Use this command:
pyinstaller --onefile <your_script>.py
https://medium.com/dreamcatcher-its-blog/making-an-stand-alone-executable-from-a-python-script-using-pyinstaller-d1df9170e263
I do not know about compiling into C, but for compiling executables in general you can use pyinstaller, cx_freeze, or a few other less common modules to create an executable folder which contains all the .dll files to run the program. I only have experience with cx_freeze so I'll discuss that here. If your goal is to have the end-user have only 1 "file" show up when they download it you need to use an installer program. To semi-quote cx_freeze documentation at: https://cx-freeze.readthedocs.io/en/latest/faq.html
cx_Freeze does not support building a single file exe, where all of the libraries for your application are embedded in one executable file. [There are modules that do this, but it's my understanding they use "hacks" that can get them flagged by antivirus software.]
You can use IExpress to compress the build directory from cx_Freeze into a self-extracting archive: an exe which unpacks your application into a temporary directory and runs it. IExpress is a utility that’s included with Windows, intended for making installers, but it works equally well if you tell it to run the cx_Freeze-built exe after extraction.
Alternatively, you can create a self extracting archive using 7zip. This is a bit more complex than using IExpress, but might provide more flexibility, and allows you to build your application using only open source tools.
Alternatively you can compile with python setup.py bdist_msi to create a single .msi file which will let the user choose where they want to install the program. At the end of the day the user will still have a directory with all the .dll files and whatnot, but they get to choose where they tuck that stuff away on their hard drive! I think this is the method most applications I've installed use. This is assuming you develop on Windows as well, if not you should include your OS on your post.

Create Java projects without eclipse?

Is there any way I can create Java projects using a simple text editor? Not an IDE like eclipse?
I want to be able to create .jar files without the assistance of an IDE, I have all the JDK commands installed already on my computer (such as javac)
I'd like to know what file structure I need, how I need to arrange my class files, what compilation steps I need to go through etc. to be able to create jar files.
Yes, completely doable (just not much fun once the project gets bigger).
I suggest if it's not a throwaway project, use a build tool like Maven or Gradle to manage your build process, so that you don't need to assemble classpaths and resources yourself, but still retain full control of the build and test lifecycle, without IDEs. This comes at a complexity cost, of course, but once it's set up life becomes easier.
See also How can I create an executable JAR with dependencies using Maven? or the Gradle docs about creating JARs
I'd highly recommend the standard Maven source directory layout too (src/main, src/test etc) as it's both commonplace and makes for easy integration with the above tools.
Follow the below steps to create a jar file
Compile the java source using javac
Create a manifest file (if main exists) to identify main class
Use the below command to create a jar file
jar -cvfm *.class
Yeah. You can create your project structure without an IDE. But it's time consuming and you have to do everything.
To talk about creating JAR, you don't want any extra software. You can use jar utility, which comes with JDK.
Here are steps to create jar:
Compile classes which you want to in jar
Create manifest file (.mf). It's needed if you want to make jar as executable. If you want to bundle classes only together, then no need. (eg. Dependency jar)
Go to command prompt and execute following command "jar cvf MyJarName.jar *.class". Make sure java is set in environment path and you're inside the directory of classes.
cvf means "create a jar; show verbose output; specify the output jar file name.
That's all. If you want to include any folders inside jar then you can use folder name in above command after classes and it must be separated by space.
Example: jar cvf TicTacToe.jar TicTacToe.class audio images

Creating a .exe for a java project

I've developped a game during a Game Jam and I'd like to create an executable to distribute it to the other team members.
The game uses the slick2d and lwjgl library. I've tried to use JExePack, but the .exe file I get isn't runnable, I get an error while launching it.
Even the jar file gets me errors.
I'm only able to launch the game on the IDE. When I launch it with the command line : java -jar "game.jar", it obviously tells me that there's missing libraries, even if I indicate the path to the lib folder.
Is there an easy way to create an executable ?
Thanks in advance.
I think using a jar was a good idea.
You need to add every required jar in the classpath one-by-one for the jar to run properly.
Launch4J (http://launch4j.sourceforge.net/) is my favorite tool for that. You can just export an executable jar from your IDE and create an exe out of it. Creating an executable jar in Eclipse gives you the option to include all required libraries in it, which saves you from adding them manually when create the exe file. The minimal settings you need are:
Input (your executable jar)
Output (the .exe you want to create)
Minimum Java version (i.e. 1.6.0)
Thats it (as far as I remember)
If you want the exe you can use exe4j, it's a very useful tool, but i think using jars is better since you can run them on every platform. Anyway, when you export the jar, check on your ide's preferences if it automatically imports the libs. (for example, on eclipse you can pack the required libs into the exported jar)
You can use Luncher4j to create an exe file and convert the jar libraries to dll files.

Decompile Java Application packed with launch4j

I have a Java application that was converted to an .exe with launch4j. For several reasons I need to get access to the class files of the application.
The first thing I tried was unpacking the exe with 7zip. That way I get a handful of class files, but definately not the whole application packed in the exe (the class files seem to belong to launch4j).
What other options are there?
You can use something like this to extract the JAR from the Launch4j executable:
http://www.nirsoft.net/utils/resources_extract.html
Typically the executable packages necessary JAR's as executable resources and then looks for a JDK on the path to execute.
Once you get the JAR file you should be able to decompile it.
You cannot get access to class files. Exes are created, So that nobody can get access to your code.
If somehow , you are able to get access to jar files then you can decompile them to get the code and make changes.

including an exe file to jar

I have written a java program that is actually works as a gui to an existing command line program.
so in basic all my program does is Runtime.getRuntime().exec("myprogram parameter");. So I have exported my java source as a executable-jar file by using Eclipse IDE and it is working nice, however I indeed need to include this myprogram.exe to the directory of the generated jar file inorder to work.
Now I am looking for a way to include myprogram.exe inside the jar file so I can keep it bundled as a single file, a method using using Eclipse would be preferred.
You can simply jar it up as an extra resource (like a .css, .properties etc.).
When your Java program runs, extract the .exe using Class.getResourceAsStream() and write it to a temporary directory in order to run it from there (since you can't run it directly from the .jar file).

Categories

Resources