How can I run main jar without JDK on a Mac? - java

I've been using the discontinued BuildDesk to compile and bundle my Java desktop application but it forces user to use legacy Java in macOS. I would like users to use latest as some users feel queazy about the word legacy.
I found a script to create an .app bundle. When I export the main jar from Netbeans (Run Target > Other Targets > package-for-store) and include the jar, libs and resources in the bundle, it runs OK but requires JDK to be installed, unlike the compiled app from BuildDesk.
Is there a way to bundle the jar so user doesn't need to download a JDK? I have found answers for Windows, not macOS. Some say no need for JDK, just JRE but I cannot get app to run if I have only JRE on my Mac.
Thanks.

this is apparenlty because of a bug in mac and java : https://bugs.openjdk.java.net/browse/JDK-7131356
which leads java 1.6 (made by apple not oracle) to be required under any circustance of running a java app.
(even if the app is self-contained apparently)

Related

Installing jre locally in windows app directory

I have a question about deploying windows application with java module.
I have windows application with several modules. One of these modules is written in java and is packaged as jar-archive. And if there's need for using this module, the application ask jre to start execute this jar.
For this time during application installation it's initialized jre installation.
I would like to understand the following.
Is it possible to install during application installation silently install jre in the application directory. So it jre copy could be used by the application.
I'm talking about structure like this:
/app
/app/jre
/app/modules/myModule.jar
So if it's needed to run myModule.jar I could do it with java from app/jre/bin ?
I saw something like that at Spark messenger (http://www.igniterealtime.org/projects/spark/). This application uses its own jre, which is installed at /Spark/jre/. But as I understand, this application is written in java and builded as a windows distributive using install4j.
I tried to find the answer to my question, but maybe I'm doing something wrong, I always find a solution of creating an exe-wrapper for jar file.
I would like to know about possibility to deploy application with installing jre locally in application folder.
You could ideally have used Java Web Start in the past.
Currently, you can use javapackager.
https://docs.oracle.com/javase/8/docs/technotes/tools/windows/javapackager.html
The javapackager command allows developers to create standalone native install bundles that do not require a separate JRE installation. The native options include: installer, image, exe, msi, dmg, rpm, and deb.
This is ideal for desktop applications, where the user may not have their own JRE installed and just wants the program to run. It may not be appropriate for server-based applications where an administrator would want full control over the environment.
https://blogs.oracle.com/java-platform-group/entry/java_web_start_in_or
In your /app/jre/bin folder there should be an executable binary called java. So in your folder /app/modules you can run
/app/jre/bin/java -jar myModule.jar
That should work.

AppBundler doesn't include binaries from JRE in OS X Java App

I'm trying to to package my java app into an OS X App Bundle and I want to include the JRE, so it can run without a installed JRE.
I'm following http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html
The AppBundler Ant Task will generate a .app with the JRE included but it is missing all the binaries.
The App will run but i'm not sure it's not using my installed JRE instead as it's missing the binaries. Or does the included JavaAppLauncher replaces the normal java binary?
The bin/ folder is not included when bundling the JRE in an app. The only native binaries it uses are in MyApp/Contents/MacOS and MyApp/Contents/Plugins/MyJRE/Contents/MacOS.
Or does the included JavaAppLauncher replaces the normal java binary?
The app bundle does not call a 'java' command. Some combination of JavaAppLauncher and libjli.dylib invokes Java dynamically.
If you are unsure if it is using the bundled version of Java, output this when your app runs. It will tell you from what location Java is being called:
System.getProperty("java.home", "")

E(fx)clipce with Inno Setup wrong jre folder name

I am following JavaFX tutorial found at
http://code.makery.ch/java/javafx-8-tutorial-part7/
which describes how to create native installer with 'Inno Setup'.
I am using e(fx)clipse 4.4 with java 8 JRE installed only and 1.8 compiler
and i do it for windows (exe).
Everything works fine, but when i install exported native application it create folders for JRE
runtime/jre8/
program wont start and says
jvm.dll is not found in bundled runtime.
if i change manualy runtime/jre8/ to runtime/jre/ - it start without any problem.
I did not found any settings in project for specifing runtime path.
How do i make my native installer make right path for runtime?
Solved. Just noticed that i was using standalone jre for project c:\dev\java\jre8 but supposed to use jre from jdk package c:\dev\java\jdk1.8.0_05\jre.
Now installer creates proper path for runtime - runtime/jre/

Java Browser Plugin Or Manually installing Java

Here is my question i installed Java Plugin for Chrome it does mean i have installed java in my machine...And after installing this plugin can i run below command
java -jar myfile.jar
through a batch file or i have to install java in my machine and setup class-path then it should work?
If i will install Java browser plugin it automatically installed java in my machine and setup path as well.
Its hard for me t understand the situation how it works. Can anyone help me on this?
The JRE is the Java Runtime Environment, i.e. the software you need to interpret and execute Java class files. The Java browser plugin is the bridge between the JRE and the browser, used to run Java classes of applets embedded in HTML.
You can check the Java plugin of Chrome browser in this link.
The plugin is bundled with the JRE, and runs inside a browser, allowing Java code to run inside the browser process on the client. The main entry point class must be written as an Applet when the plugin is used, but all the Java code it calls can be just regular Java.
There are limitations when running Java code with the Java plugin for security reasons. All code shall run within sandbox with limited access to the file system and such.
Also as the plugin check for installed JRE version at your machine, that means you do have JRE.
You can install as many JDKs as you like. Just put them in different folders.
The one you refer to on the path is your choice - but presumably you'd choose the one that you want to use whenever you type "java ...." commands at the command line. In the absence of any other factors you should probably set this to be your most recent JDK version.
Note that your IDE may support multiple JDKs, for example Eclipse has "Preferences / Java / Installed JREs" where you can set up multiple JDKs/JREs for use with Eclipse
Please first check your machine contains java (jdk or jre)
java -version -- if you get a valid output then you have java in your machine.
in order to run java -jar myfile.jar , you should install java (jre or jdk) in your machine and class path set to the relevant location. To run this you should install jdk or jre in your machine. Most program only need the JRE (Java Runtime Environment) but some programs need the Compiler at runtime in which case you need the JDK.
Please refer this link to find out How to set class path .
Then you will be able to run your command.

How to bundle a Java dependent application with a JRE in an MSI

This is similar to How can I create a .msi file for a Java program ? (eclipse) but is specifically about bundling a JRE as well.
I am currently working on building an MSI for my product so it can be installed as an add-on with Windows Home Server. The installer must be a silent MSI installer.
My product depends on Java 1.6. I want to bundle Java inside the MSI but not necessarily install the JRE, simply copying the files to my product directory and executing from there would be fine.
Initially I tried installing the JRE anyway as a first step. I used the JRE's silent installer, however it turned out that because the JRE installs itself via another MSI, under the covers, the one-MSI-installation-running-at-once rule was broken, and so a JRE could not be installed.
So I changed to copying the JRE files instead. I have managed to create an MSI with all the items, but it comes in at a whopping 60MB! That's around 33MB for my app and the rest is the JRE. My normal setup.exe which bundles the JRE is about 30MB, so I am assuming compression is much better in the latter case (I also use Pack200 compression there).
I am using WiX to build the MSI and have compression turned on.
What is the best way to bundle a JRE, with dependent application, inside an MSI?
IMHO you should simply add whole (unpacked) JRE directory to your installer files. Then run your JRE from the given, known path. Many products (for example DB2, Oracle 11g and even WebSphere Application Server) are doing it exactly like this.

Categories