OpenJDK not mapping to openfire

In our project I bundle openfire along with other application which itself included java bundle inside that. Recently we have update to openfire 4.7.5 version where they stopped to provide jre inside openfire. Our intension is that we dont want to have external java in our system, since we have provided jdk inside our package I want my openfire to point or use the java i have inside my bundle. And i dont want to set java_home ENV manually.

Maybe you should consider modifying or replacing the start and stop scripts for Openfire in your bundle, to point at the distribution of Java that you ship within your bundle.

Thanks for the quick response
In the bundle i am having the openfireStart.bat file which calls the openfire-service.exe(inside openfire/bin) file with /install command. I dont know what else should be added on this to use my internal java. Is there any param or other command to call openfire-service file.

I think you can set the JAVA_HOME environment variable in the bat script to identify the version of Java to use.

I have added SET “JAVA_HOME=myInternal jdk location”
<openfire-service.exe file location> /start
in openfire_start.bat file. When i ran this bat file it prints Service is starting. but in task manager i could see openfire is started and i even tried to start from services but it says - Windows could not start the openfire service on local Computer. Error 1067: The process terminated unexpectedly.

Hmm, I expected that to work. Sadly, I have no ideas other than setting the variable in the OS.

you could bundle it yourself. Create your own JRE folder within Openfire’s folder

I am curious why bundling the jre is required. Is this mandatory?

If you are deploying on Linux you should ideally use the Java versions within the repository of your distribution, these often are patched to work better with the distribution.

Or follow speedy’s advice, and look at the following which is how Arch Linux wraps Openfire with a script, change /usr/bin/java to the path of your bundled Java:

To install our application java is required since its a jar file. But once application is installed I may uninstall the java which i used to install my application but to start openfire and other application i want java so instead of depending or relaying on the external java which is used during installation i want to use my java which i provide inside my application. And my application is windows based server.

This seems over-complicated, why not just keep the system installed Java? Bundling the same version is no different apart from the fact it is not in the windows path (it is not globally executable).

If you still want to continue with bundling, please follow speedy’s advice above, and also my advice in my previous post, the step by step is:

  • Pull JRE from whatever you want (OpenJDK or Adoptium, whatever)
  • Install it in the Openfire directory under some directory such as jre as speedy has recommended.
  • Write a wrapper script for Openfire (using the example above) to execute the java within the jre tree and then pass the relavent path to Openfire jar to execute it.

Hope this helps.

To summarise this,

We are using Openfire v4.7.5 with our OpenJDK 11 copied in the local folder. While trying to run Openfire as a service, it always takes the precedence of the JDK installed in the local machine instead of our own OpenJDK folder.

Used the following command to install as a windows service:

  • Openfire/bin/openfire-service.exe /install
  • Openfire/bin/openfire-service.exe /start

Once the service is started, log into the admin console to check the java used with Openfire. it shows the installed java8 instead of OpenJDK 11.

APPROACHES TRIED:

Approach 1 :Setting JAVA_HOME in the system environment variable to our OpenJDK folder.
Result: it’s working and mapped our OpenJDK folder. But we don’t want to set JAVA_HOME in the env file.

Approach 2 : Tried copying entire OpenJDK folder inside Openfire as JRE.
Result: It’s working, but we don’t want to copy entire JDK to Openfire folder, as its already available in another location in same machine.

Please suggest an approach to map OpenJDK folder to Openfire when running as a service.

It is very possible that there simply aren’t other options available, with the service that ships with Openfire. Your ask is somewhat of an extraordinary one, which seemingly is very specific to the exact way you’re using Openfire in context of a larger suite of applications. I’m not sure if there’s a generic case to be made for something like what you’re after to be supported by Openfire.

The Openfire service is generated by a third-party application, called Install4j. You could look in their documentation for additional hints. A cursory look didn’t show anything useful to me.

If what you’re after is indeed not possible with the service executable that we ship with Openfire, you could consider developing your own service executable for Openfire. You could probably even use Install4j for that yourselves - our install4j configuration is part of Openfire’s source code. Alternatively, you could try to engage with one of our commercial partners, for them to develop the desired functionality for you.

another option may be to use symlinks. you could create a link for the jre folder inside openfire to the desired location of your jre

Since this is windows, shell scripts will not work.

It should not be difficult to write a batch script to wrap the Openfire jar, and dump install4j entirely. This is what Arch Linux does for distribution. The batch script should call the java executable and then provide the path to the Openfire jar with the -jar flag. Simply converting the wrapper script I linked from Arch Linux to a batch script should work.

Install4j is designed to make it easy to install Openfire, if you are doing anything custom it is likely just to get in the way, but this is opening a can of worms which could be difficult to administrate.

I’m not sure if you can get Openfire installed as a Windows service that way though. That’s another executable that Install4j generates (but which you don’t even get to see in Arch).

After some reading, Microsoft allows you to set a binary as an executable service (which I assume means it will start running it in the background, I don’t use Windows and haven’t done for years), see: sc.exe create | Microsoft Learn

You mean the service? see: openfire.service · main · Arch Linux / Packaging / Packages / openfire · GitLab

If not, and something else is missing, please let me know as I run the Openfire package from Arch Linux for my instance, I can report the issue to them (I have reported previous issues in the past).

Also I noticed something:

Speedy solution here is likely the best one, I believe they were quoting: install4j Help - JRE bundles

There is a tool to create a bundle too, maybe I should have done a more thorough search before suggesting writing a wrapper, I am just used to scripting anything myself, and you can’t really go wrong that way.

For time being, we have decided to go with symlink with our OpenJDK. In future, if needed we will explore more on to use Install4j to customize service exe.

Thanks for the suggestions guys @Polarian @guus @speedy

No problem, glad you found a solution :slight_smile:

A little note, symlinking to path will result in all java programs using that Java version… if Openfire is the only Java program you are using then its not a problem.

Take care.