How to bundle a JRE with Launch4j? - portability

I have Launch4J on my computer and it's a great program. One of its features I'm interested in is the ability to bundle a JRE in the general .EXE file. However, I can't find any documentation that describes how to go about doing this.
How do I bundle a JRE with the EXE? Plus, where do I get a compact, portable JRE to run? The download links on Oracle are for the installer packages.

After some attempts i finally get a workaround to bundle the jre in my application:
I package my app as a zip file with the following folders inside:
containerFolder
|- jre
|-bin (in bin there is java.exe)
|-lib
|- cfg (to save the user configuration, but it's not needed)
|- bin (my application with the .exe and the .jar and all the other stuff)
In the xml file of launch4j i configure the jre like this:
<jre>
<path>../jre</path>
<opt>-DgvSIG.confDir=../cfg</opt>
</jre>
The trick here is that the path is not to the java.exe file. The path to the jre is relative to the position of the .exe and it should point to one folder before the java.exe file
The jre folder i'm using is just a copy&paste from the jre folder installed on a windows system.

I did the following and it worked for me using ver Launch4j 3.11:
Created a new folder for my application (called for example
MyApp).
Copied the jar file from the java project dist folder to the MyApp
along with the lib folder.
Created a folder called jre in my application folder MyApp
so now MyApp folder contains:
MyApp.jar
lib <- this has the libraries needed by my java app.
jre
Copied the bin and lib folders from java jre folder (C:\Program
Files (x86)\Java\jre7) to MyApp\jre
In the Launch4j having set all the required options, then set the
Bundled JRE path to "jre"
Make sure that in the search options "Only use private JDK runtimes"
is selected.

The same problem like you mate. No worries now. Its all solve with the maximum depth to solve future solution.
Solution how you can bundle your JRE for your jar without the need that the user has to install java or not. Your java application will run.
Copy lib and bin folder from your JRE folder to your project dist folder
open launch4j and enter the following setting.
The trick is you need to give the full path to the including javaw.exe.
Enjoy!!!!

I have just done this. Above clearly describe the method for bundling jre.
Here, I just share an experience that I have struggled. If you want to create an installer exe after created wrapper exe by launch4j, pay attention to the file path for launch4j and jre. This is my path I used to solve my issues:
launch4j, bin/jre, resources/bin/jre.
launch4j, bin, and resources are at same level.

The jre can usually be found in your SDK folder. Yes the links online are installers, but once it installs, the JRE is now located on your local disk. Mine is located in
${jdk folder}\jre
The parts that you don't need from the JRE could probably be removed manually if you really wanted (I'm not sure whats available online).

A working example of using Launch4J to bundle a Java application with a specific JRE can be found at https://github.com/vZome/vzome/blob/master/desktop/platform/windows/README.md. This particular distribution is configured to require vZome to use the bundled JRE rather than any JRE found on the target platform.
Hope this helps.

Related

Error while importing projects

While importing projects into eclipse i have this error:
Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory. Could not execute build using Gradle distribution 'http://services.gradle.org/distributions/gradle-1.11-all.zip'.
As I have checked i need to set JAVA_HOME (i have the JDK on my computer), but i dont have a clue how to do that.
I had lots of similar problems and I think that the best solution is to specify JDK location manually. In order to do it:
Add two files to project root folder
gradle.properties:
org.gradle.java.home=C:/Program Files/Java/jdk1.7.0_03
and local.properties:
org.gradle.java.home=C:/Program Files/Java/jdk1.7.0_03
You should change org.gradle.java.home value to JDK path in your system. If you will have the same problem with android SDK add sdk.dir=/Users/alonzilberman/Android/adt-bundle-mac-x86_64-20130917/sdk to your local.properties.
After adding files refresh gradle build.
I got the same message while trying to build a project in Android Studio.
After hours of research, trying different versions of JDK (from 8 to 6) I found this answer that fixed my problem:
https://discuss.gradle.org/t/mac-gradle-issues-with-finding-using-jdk-7-the-usual-answers-to-this-question-arent-working-expert-required/2553/24
The reason was that the AUSKey package installed a tools.jar in /Library/Java/Extensions directory that derailed Gradle looking for the compiler. Removing that file fixed the problem and I can now build in Android Studio.
Create a new system variable called JAVA_HOME and add
C:\Program Files\Java\jdk1.8.0_25
It's because your environment variable isn't pointing to your jdk folder. Don't point it to your bin folder.

Deployment- Java Application

I have created a Java application. And its ready for deployment.
I have made jar file from my code. wrapped it using launch4j and bundled jre with it and accessing my exe file(generated by launch4j).
So,No need to install JRE and Everything works fine.
But one small problem is that my Exe file has to be at some predefined relative path to the Bundled JRE.
For example let say user has installed it in E:/(My Soft) where My soft contains JRE files an my Exe file. Now if user copies the exe file to his desktop then he will not be able to execute it.
So, I want to is there any way i can bundle jre within my exe or any other tweek so that user can Execute the exe file from anywhere on his pc ?
Try use jnlp starter for your programms. Read more in official oracle documentation JNLP
There's one option to bundle JRE with exe is to create a Portable Edition app with for example jPortable. So you can execute exe anywhere on the PC without installing JRE. But the better option is to create a custom installer which will check current installation of JRE in the client PC and install it as an required option if no other compatible JRE found.

Cross Platform java development with Eclipse (Build Path issues)

I have 3 partitions (and the required one that Windows will generate). One contains Windows, one contains Ubuntu, I also have a ntfs partition named Data that contains my Development folder that I use as storage between the two environments.
So in Windows it is located at: D:\Development*
In Ubuntu it is located at: /media/Data/Development/*
Whenever I set up my environment, everything is great as far as the source files, but whenever it gets to the point of the build path, it is expecting the absolute path from the previous platform I was working with (so swapping to Windows from Ubuntu it is expecting things located at /media/Data/Development/* and when switching to Ubuntu from Windows it is expecting it in D:\Development*).
Is there a way to use relative paths such that if I open the project in Windows or Ubuntu it doesn't require modification of the build path?
Place the libraries jar files under a lib directory in your Eclipse project, and use a project-relative path (using "Add jars" rather than "Add external jars") to include these libraries in the build path.

JDK as Zip File only not JRE

Where can I get the latest jdk as a zip file. I don't want the jre, I want the full jdk. I can't run exe's or even request windows installer so it's impossible for me to download the .exe and run it. Also I can't access some uploading sites like Drop box or 4shared. Is there any ftp or place that I can get just zipped up jdk? Thanks you very much. Jportable is not good enough, Thanks.
http://installbuilder.bitrock.com/java/ all the version are available. enjoy. all are ZIP
Ideally, Oracle would provide us with the option of downloading the JDK binaries as a ZIP package instead of forcing us to use the Windows installer. But since they don't, why don't you try downloading the ZIP distribution of another Oracle product that already includes a JDK (e.g. Oracle SQLDeveloper). And please be sure to come back here and let us know if this approach worked out for you. I'm sure there are tons of folks out there looking for workaround too.
It's really simple but, you have to make it yourself.
First, download the JDK from the Oracle Website.
Second, extract all the contents using 7zip or other extracting utility.
Third, navigate through the extracted content and use Java's "unpack200" to convert all the ".pack" files (there's a couple of them) into jar files. You can delete the ".pack" files afterwards if desired.
Note: In order to use unpack200 you need to have a JDK installed on the system. Navigate to the jdk1.x.x_xx/bin folder an run the utility from the command line.
Example: unpack200 rt.pack rt.jar
Thanks.
You can install jdk (with installer, uncheck 'public jre' option), zip installation folder.
Then uninstall jdk. Now you have a jdk zip, you can unzip wherever.
I'm using jdk this way on Windows Vista, both jdk 1.6, and 1.7.
I was also facing the same issue - to get a zip version of JDK7 on my PC. Tried to extract the exe installer and was happy to find that I got a set of folders including jdk,jre, lib,bin etc (similar to the set up that you get by running the installer for Jdk8). But my happiness was short lived - Eclipse did not recognize this path as a valid JDK / JRE installation , while I set up the additional Run time environments.
The fix is to run the exe installer and install it in a different path , outside Program files, so that it doesnt mess up your Java home settings or JRE versions for other client programs.

Need help in Installing JRE?

i have to install JRE Programmability if the System does not have JRE, i had dected JRE is installed in the system or not, but i have no idea how to install JRE programmtically, some people said you can use installer, but i donot know how to use installer for this purpose i searched in sun documnet, installing JRE in slient mode, there's also i donot know how to use that command iie.fing.edu.uy/ense/asign/…
In order to run your Java program, you can do that without installing the JRE, that its, you can run the application in a computer without JRE, we do that every day.
The way is to deploy you application with an embedded JRE and use a script (.bar, .sh) to execute you application using the embedded JRE. So your application is self-contained and no requires external JRE. You need to copy the entire JRE folder into your application and start removing unused files using the test-error approach. You can also decrease the file sizes removing not needed classes, like in rt.jar (you can decompress, remove unused classes and zip again).
The problem with this approach is that you are violating the Oracle/SUN JRE distribution policy as you are distributing a JRE with fewer files. If the application is for internal use, I think it's OK, if you want to redistribute the application, you are in trouble.
Another question is how to install the JRE by code, you can try to ship the JRE with your application, using an installer detect if JRE is already installed and install it id needed. Doing that in Java code is not trivial, you can use Runtime to exec external programs...
Do not rely on JAVA_HOMEas is not actively used nowadays.
Example:
Say you application name is 'A', you folder structure can look like:
A
|-> Run.bat
|- jre
|- bin
|- lib
|- lib
|-> A.jar
You application main class is Main.java in package a. Your Run.batcan look like START "" jre\bin\javaw.exe -cp lib\A.jar a.Main
You only are calling the embedded jre in jre folder, by calling the bin\javaw.exe and passing the jar and main class. The jre folder can content and entire JRE as copied from c:\Program Files (x86)\Java\jre6\ (Windows 7).
If you can have a web based solution you can use deployjava
http://download.oracle.com/javase/6/docs/technotes/guides/jweb/deployment_advice.html

Resources