Is there a way to bundle a spring-boot application into one executable jar including a JRE?
I think I saw someone doing that (Josh Long?) which resulted in a jar you could start via java -jar foo.jar and even with ./foo.jar
I googled for this the last hour but couldn't find any documentation on this, anyone there to help me out?
EDIT:
I just found what I saw at the conference. spring-boot 1.3 introduces something called executable jars, which wrap the jar with a shell script.
Enabling this makes it possible to run your jar like ./my.jar and tying it to an unix init system.
However, you still need java installed at your host.
Enabling this feature in gradle is as easy as adding this to your build.gradle
springBoot {
executable = true
}
You should think about using a Java installer / wrapper which will create a native binary which contains your code / jar and the JRE (some solutions can even download a JRE for you)
The positive side effect is that you (if needed) can create solutions for Linux, Windows and Mac.
If you want to stick to a simple Linux only solution you might want to try this: Bash script containing binary executable
Propably you are using Maven. This maven plugin allows you to create single jar file with all dependencies. Next you can use tool such as jwrapper which allows to build executable file with embeded JRE for many platforms.
Related
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.
I want to run a java program as an exe in Windows. The windows box doesn't install java at all...
So, is there any other way in which the java program can be converted to an exe which removes the need for a dependency on the JRE?
You can use Excelsior JET compiler for that purpose.
See http://www.excelsiorjet.com/ for more information on this.
You can ship the JRE with your application and use that JRE for your application. The effect is the same: The application will be started through an executable (wrapper needed) or script (batch) file and the target machine does not need to have a java runtime installed.
Java doesn't have to be 'installed', it just has to be 'present'.
For the application to run you will need the runtime. In fact the very first thing that happens when you start the app is a call is a made to OS to start JRE. You cannot do without JRE.
[You can of course embded JRE into your app itself if you want].
I have used JSmooth to exify my application. It also allows for embedding a JRE inside. I just used the "ensure that at least Java X is available".
GPL, can be run as an ant task.
Well given the fact, that you are requesting an executable file (exe) in Windows, there is another approach:
Use IKVM.NET - Bytecode Compiler which converts Java bytecode to .NET dll's and exe's.
Get the latest version of IKVM.NET here.
Use this command
ikvmc -target:exe -out:foo.exe yourJarFile.jar
to create your .NET executable file.
After this, you can use your exe with the mandatory IKVM dll's or if you prefer one exe file, you can use ILMerge in order to get a single executable file:
ILMerge.exe /target:winexe /targetplatform:"v4,C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1" /out:C:\foo\bar.exe foo.exe <IKVM dll's>.dll
If you are using JDK 9 and above then you can use jlink. It will include all the necessary modules, header files, security policy files, etc, and build a minimal runtime image. This image can be shipped directly to the customer. You can specify your own launcher and what not.
jlink description:
You can use the jlink tool to assemble and optimize a set of modules and their dependencies into a custom runtime image.
Read more at oracle docs: Java Platform, Standard Edition Tools Reference.
GCJ can create native code from Java source files. Here's a tutorial on how to build it in Windows.
Have you tried install4j? There are various versions, some free, of this concept. Basically, this application compiles your application into an executable installer, specific to the OS of your choice.
Easiest way to do this task is to use the launch4j for the windows exe wrapper and then use inno setup to create the installer. When you are creating the installer for the you application add the folder under the other application files. Make sure jre is inside the folder.
Work done!!!
I'm very new to java. I'm developing a tool that checks if your PC meets some set of specifications. This included writing and executing a separate batch file and including an API (SIGAR) for the model of the CPU.
My problem is that when I tried exporting it to Runnable JAR in eclipse, and I ran the resulting JAR from command line, it gave me lots of 'DLL not included in build path' Exceptions. After including the folder that contains the API DLL in the build path, I got similar exceptions. The thing that fixed it was adding the folder containing the DLL to environment variables (PATH) in Advanced System Settings.
Questions:
The JAR now works fine on my computer, but what about the users who download the JAR? Will they also need to add the DLL to environment variables? If so is there a way the JAR can do that for them?
My JAR won't run with a double-click, but will run from command line. Is there any way around this that will carry over to users who download the JAR too?
If the user downloads the tool and can't run it because they don't have the right version of the JRE, will the tool notify them? If not, is there a way around the user having to update JRE or will wrapping as an EXE suffice?
Thanks in advance, much appreciated. Lots of questions.
Q1: The JAR now works fine on my computer, but what about the users
who download the JAR? Will they also need to add the DLL to
environment variables? If so is there a way the JAR can do that for
them?
You can put a DLL inside a JAR file:
How to make a JAR file that includes DLL files? (Hint: read both answers ... completely.)
However, when you distribute a JAR containing a DLL, you then have the problem that different platforms require different DLLs (or whatever). Even with Windows you have the problem of 32 bit versus 64 bit DLLs.
Q2: My JAR won't run with a double-click, but will run from command
line. Is there any way around this that will carry over to users who
download the JAR too?
You cannot address that problem in a JAR file. The "double-click to run" functionality is implemented by the OS. The best way to provide this kind of functionality is using (platform specific) wrapper scripts that are double-clickable.
Q3: If the user downloads the tool and can't run it because they don't
have the right version of the JRE, will the tool notify them? If not,
is there a way around the user having to update JRE or will wrapping
as an EXE suffice?
Unless you have a JRE installed, the JAR file is just a passive blob of data. (A ZIP file, actually).
If the user has a JRE that is too old, then either the JRE will be unable to load any classes in the JAR (because the classfile version number is wrong), or you will get errors because of missing (system) classes.
The only hope would to do something like providing a wrapper script to launch your application that checked the JRE version before attempting to launch the JAR.
As a general rule, if you want to do fancy stuff like this you need to distribute your program in an installer, not as a bare JAR file.
I have to create a jar file wherein i need to add external jar files in the classpath, properties files, in such away as to run it on any other machine.
You could either use manifest.mf to define external class path or use script that composes classpath and runs your application.
I really recommend you to use a build tool such as Maven for these things:
http://maven.apache.org/
How can I create an executable JAR with dependencies using Maven?
Regards,
Boskop
You can make the jar in almost any IDE. I agree with Michael SchmeiBer, be a bit more specific please.
I use eclipse as my IDE (because you can both use it in windows and Ubuntu Linux) to make a jar (you can define the startup class in the jar).
I use different methods for starting up of different machines.
I use nsis to create a nice windows executable (.exe) You can include your own icon.
In nsis script you actually use the same command you would use in a batch command.
nsis has some nice features, like search for a java jre.
For Linux and Mac I use a .sh file with this command.
I have a Swing desktop application and have created a jar file which depends on library (which is kept in ./lib/) and a .txt file in the same folder. Now to execute the jar I have written a .bat file which checks if Java is installed or not. If installed then I run the jar file with command:
javaw -jar TagEdit.jar
Now there are two problems I am facing with this:
I would rather prefer a single executable, if possible.
As using bat file, the console is visible in back (looks kind of weird). Is it possible to turn it off?
Java is everywhere, and there are lots of applications that are built in Java and packaged in a setup, or given as exe. I Googled a lot but could not find a way to create a setup for the software or an exe. How are those software packaged?
Have tried jlaunch, but could not get that to work correctly.
Himz, Eclipse can automatically build a so-called "fat-jar" for you. It is a jar that contains all the dependencies you need.
If you are a happy Maven user, then you have two brilliant alternatives - the shade plugin, and the assembly plugin. They both can produce a "fat-jar" for you. :)
There are various answers to this.
javaws.exe will execute the jar without the console appearing behind
But I feel this isn't really the best way.
I think should investigate using Java Web Start, So you create a JNLP file and have it jar downloaded from the web, I think, you can also have a desktop icon.
If you don't want that
I think you can get/buy binary wrappers for the jar.
You could convert it to an executable. Try Googling java to exe.
Once that is done, you could package it up as an installer using NSIS.