I am using install4J to distribute my application . However i am using serial port in my program therefore i will need the below file to be copied to the target JRE folder
%JAVA_HOME%/lib/ext/comm.jar
%JAVA_HOME%/bin/win32com.dll
%JAVA_HOME%/lib/javax.comm.properties
Is there any way i can do it by getting the Java Home Path via Install4J ?
Thanks
Since JAVA_HOME is not a Windows variable, it will be tricky to get it, and Install4J does not have a JAVA_HOME variable to my knowledge. While JAVA_HOME could be set on some computers, it is not safe to assume it is set on all computers.
What I would do, personally, is not touch the user's JRE. Bundle your own custom JRE with those files included into your install file generated with Install4J. That way, your program will always work with its own custom JRE that is independent of the system's JRE.
Copy the files to
${installer:sys.javaHome}
This is the JRE that the installer and subsequently your launchers run with. If you bundle a JRE, the value of this variables changes after the "Install files" action runs.
Related
My application uses authentication through a LDAP server over SSL. This requires installation of certificates in the bundled JRE's keystore. I use a script to do it through Java code and in the process need to find the location of the installed JRE. This script is executed at the end of the installation.
On Windows, it's relatively simple: I just use context.getInstallationDirectory() and then add jre\lib\security\cacerts.
On Mac OS, however, the JRE is installed in a different location and I would need to use the actual sys.preferredJre or the java.home property. The problem is that I can't access them from the scripts. The context object doesn't seem to have the corresponding methods. System.getProperty("java.home") returns a temporary location where the JRE is probably first unpacked and not the final path.
context.getCompilerVariable("sys.preferredJre") returns null.
As a side note, there doesn't seem to be any logging from inside the scripts. All I get is a brief message about the script succeeding or failing. I had to write to a custom file to get any information.
Can you suggest a way to handle this? Ideally, I would like to do it in OS-independent way and just get the Jre directory.
Thanks in advance
Sasha
After the "Install files" action has run, the sys.preferredJre installer variable is set to the directory where the bundled JRE has been installed. You can get this variable by calling
context.getVariable("sys.preferredJre")
In your question, you use getCompilerVariable, which is not correct because it returns values of compiler variables.
I want to set my java_home variable,
but have a custom enough OS not to be able
to find my jdk dir as prompted everywhere
(it's a chromium os, and has installed jdk8 by chromebrew...).
What i have is a usr/local/jre folder,
and few java* binaries in usr/local/bin.
Can the jre I have be the same that
everyone refers to as /usr/java or /usr/java/jdk?
The jre folder includes a bin, lib and plugin folder and some tl;dr files.
Thanks a lot!
There is no "standard" definition for the JAVA_HOME, that is you can point it to the folder where either the JRE or the JDK is installed.
The only requirement (which is in fact more of a generally accepted convention) is that $JAVA_HOME/bin/java should start the Java runtime.
This happens if you point JAVA_HOME to either the JDK or JRE folder, in both cases there is a folder /bin and inside the "java" executable.
In your case, since you identified the JRE installation folder, you can point JAVA_HOME to it.
I'd like to create a single executable file for Windows with the JVM packaged inside of it.
Therefore, the user will be free of installing java and assigning the JAVA_HOME system variable.
I can't find an appropriate guide for this stuff.
I think you want to use Launch4J, which is exactly what you need.
Here is a link : http://launch4j.sourceforge.net/
It packs a jar into a exe with the JRE inside.
I want to create a executable jar file of a small game that i wrote in java and make it playable in any machine with simple double click like exe file. My question is do you need to install java runtime first in order for executable jar file to work or can it work on a machine without any java installed as well?
No it can't. However, clients do not require the JDK, the JRE would do.
You can make your jar declare its own main class and have users double click it normally like an exe file or create a bat file in Windows.
It requires a JRE instance to be installed on the host machine. This is because JAR files are actually executed via a command line like (in Windows):
java -jar ...
This means that somewhere on your system the java.exe executable should be reachable, either by including its folder in the PATH (Windows) or replacing java with its full path.
Also, most likely you will need to have all the runtime Java libraries to be hosted on the system, as the JAR file containing the application you want to run is not supposed to contain all the Java API libraries. They are also part of the JRE package.
My explanation is tied to Windows for the sake of examples, but it can be extended to any OS.
Do you need to install java runtime first in order for executable jar file to work?
Yes, of course. To run Java .jar files first you need to have installed at least the JRE (run time environment). The JDK (development kit) is a superset of the JRE and will also work for running .jar files.
Can it work on a machine without any java installed as well?
No, as mentioned above, at the bare minimum the JRE must be installed.
You have to have a Java runtime environment (JRE) available on the machine unless you use a tool that performs ahead-of-time compilation (AOT, which is contrast to the usual Just-In-Time). Such tools are available (such as Excelsior JET), but they have a number of downsides, including cost and the fact that a precompiled Java application is a regular executable and will only run on one operating system. I've seen some installers that will detect whether a JRE is installed and launch the Java installer for the user if not.
Yes ! of course, JRE is required and it is not compulsory for JDK to be installed. Since, the main class is defined in JRE for .jar files, it is necessary to have JRE on your machine. I tried with Windows OS.
Actually you can bundle JRE within your exe file with several java .exe wrappers.
Here are few of them JSmooth, Launch4j, Jar2Exe.
This question already has answers here:
How can I get the latest JRE / JDK as a zip file rather than EXE or MSI installer? [closed]
(30 answers)
Closed 8 years ago.
I have seen many products bundeled with JDK, I wonder if there is a way where one can install JDK by simply unzipping contents to a directory, so there is no icon created in add/remove programs, no registry entries etc.
Also in this case:
How can we configure Java plugin for browsers?
And how can we configure settings as seen via Control Panel entry for Java?
According to this, I created a batch script to build jdk archives automatically.
The essential parts of the link are:
Create working JDK directory ("C:\JDK" in this case)
Download latest version of JDK from oracle (for example "jdk-7u7-windows-i586.exe")
Download and install 7-zip (or download 7-zip portable version if you are not administrator)
With 7-zip extract all the files from "jdk-[6-7]u?-windows-i586.exe" in directory "C:\JDK"
In command shell (cmd.exe) do the following:
change directory to directory C:\JDK.rsrc\JAVA_CAB10
execute command: extrac32 111
Unpack C:\JDK.rsrc\JAVA_CAB10\tools.zip with 7-zip
In command shell (cmd.exe) do the following:
change directory to C:\JDK.rsrc\JAVA_CAB10\tools\
execute command: for /r %x in (*.pack) do .\bin\unpack200 -r "%x" "%~dx%~px%~nx.jar" (this will convert all pack files into jar)
Copy whole directory and all subdir of c:\JDK.rsrc\JAVA_CAB10\tools" where you want your JDK to be and setup manually JAVA_HOME and PATH to point to your JDK dir and its BIN subdir.
Yes, you can create a zipped up JDK, unzip it on the target machine and run java, javac, etc. from that directory to your heart's content.
The easiest way to create such a zip file is to install the JDK on a machine and then zip up the contents of the JDK directory. We do this in certain circumstances where we need to control exactly what configuration of Java will be used in our deployments. In that case, our scripts just point JAVA_HOME (or the equivalent) to our internally bundled JDK instead of relying on a sysadmin to install exactly what we need prior to arrival.
In terms of integrating with the browsers, that can be a bit more problematic. The short answer is no, you can't integrate directly with the browser without some sort of installer.
You could use SysInternals RegMon and FileMon (now owned and dist by MS) to see exactly what is modified by the Java installer. I believe there will be a number of reg entries that you will want to create. Products like WISE installer, for example, also use this sort of approach under the hood to repackage product installations (e.g. as MSI).
Please be careful since there are also some dynamic decisions made by the installer which may affect what gets installed (e.g. on XP v.s. W2K3 server). I was bitten by this once regarding installed codepages. I do not recall the precise details, but the effect was that a codepage file was missing in my embedded JRE + JDK (legally redistributable portion only). This caused a very bizarre and seemingly nonsensical runtime error in my code. It goes without saying that the same applies to Server v.s. client JVM DLLs.
Really, no, at least if you want to use it from Windows and not from, say, cygwin. Windows depends too much on the registry; you could simulate the registry updates necessary, but software that moves the files to the right place and updates the registry is called "an installer"; you'd just be reinventing the installer.
I believe this at least used to be feasible to a limited extent with earlier versions of Java - I don't know if it still is.
Most of the registry entries are used for things like browser plugins, as you mentioned in the question. If you just want to be able to run Java (e.g. from a batch file), that's one thing - but really installing it is a different matter. Even if you're just wanting to run it, you'll need to be careful to always explicitly use the one you intend, rather than using the installed one accidentally for part of your application.
What's your actual use case? Do you actually need a browser plugin? What aspect of the configuration are you interested in? A lot of the control panel configuration is to do with updates and browser integration. Many other aspects can be controlled using command line options to set specific system properties.
If you just want to provide a JVM with your application is fine, but more than that I would not recommend.
If you just want to have the JDK (JRE) files, you can run the installer within sandboxie. Once installed in the sandbox, just copy the files from c:\sandbox and you are done.
I'm using this to compile and run legacy java applications which cannot be migrated easily to a newer version of java. I can point Eclispe to this JDKs and tell it to be compliant to Java 1.3.
Just down load the Windows server version of Java from the Oracle downloads page. Setup JAVA_HOME and PATH variables on your own.