1

So this is pretty simple, I am running a set of tools on windows, however to avoid issues regarding a lack of java installation I have bundled with my installation its own jre folder which in windows allows me to simply run a java virtual machine with a .bat and run my program.

My question, am I able to do the same on linux without java, I know my program works fine on ubuntu so far as long as it has java installed, but I am now running into issues regarding certain linux computers that do not have java installed at all. How would I call the java folder inside my program to run a virtual machine to run the .jar? Would it be the same process? I already have a .sh that opens java and runs my virtual machine , it starts with a java command followed by -jar. example: java -jar -xmx1024m ./myprogram.jar .

How would I change that command above to use a java or portable java installation inside my program folder? how can I create a portable java in linux also as I am pretty sure that the jre folder I have which works on windows will not work on java.

0

The first step is to download a portable copy of the JDK for Linux. OpenJDK may be a better option, but since some programs refuse to run with it, here I'll demonstrate using the Oracle JDK. DISCLAIMER: if you're going to be redistributing this then you need to be careful that you're not violating Oracle's EULA.

So with that out of the way, head over to JDK download site, accept the license agreement, and then select the .tar.gz Linux option:

enter image description here

Save it in a clean directory of your choice. After the download has completed, open a terminal window and cd into that directory you just created.

Now we need to extract the archive:

tar -xzf jdk*.tar.gz
rm jdk*.tar.gz

You now have a portable JDK. Next, copy your JAR file into the directory as well.

Now we just need to create a script to launch it. Let's use nano:

nano launchApplication.sh

And paste in this text (replace helloWorld.jar with your JAR filename):

#!/bin/bash

jdk*/bin/java -jar helloWorld.jar

Now press CTRL+O followed by Enter to save the file. Now exit nano with CTRL+X.

Now that we've created the script, we need to make it executable by running the following command:

chmod +x launchApplication.sh

Finally, you can run your program with the portable JDK by doing:

./launchApplication.sh

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.