Can we run multiple java versions in parallel for different purposes? - java

I am using Elasticsearch which uses Java 8. I also want to install kafka on the same machine but kafka uses java 11. Both services are to be run in parallel. Can anyone tell how can I run both java versions at same time?

Manually download and unpack Java
https://adoptium.net/releases.html?variant=openjdk11
https://www.azul.com/downloads/?version=java-17-lts&os=windows&architecture=x86-64-bit&package=jre
Instead of simply starting java with the
java -args commandline,
you can start it via /install/path/to/java/bin/java -args
or, for windows, use C:\install\location\bin\java.exe -args
You might want to make some start scripts / batch files for that, depending on the exact requirements of your system and Elasticsearch and kafka and possibly other software.
That's it.
one little addition:
If you can NOT directly call java, or the software starts more java apps via the 'default' java, you can also use scripts to manipulate the PATH variables of your system before starting the app. Then you (and your apps) can simply call java -args again.

Once you download different versions of JRE(java runtime environment) to your local, if you use Eclipse IDE, you can checkout different projects in single workspace & specify Java Build Path with JRE version you want.
This way, you can run multiple applications having different versions of Java.
I think other java IDEs also have this kind of support.

Related

How do program specific local Java installations affect performance?

When installing Minecraft, it installs a local installation of Java. When running Minecraft, it uses that installation. I see the advantages about updating and multiple Java versions, but it does this regardless of any actual Java installations on my PC. My Java version is always up to date.
I usually have a bunch of Java programs open and always running in background. How does starting a VM from a separate installation affect performance? What are pros and cons of such an installation method? (Although I know most of the pros from Mojang). What if many other programs did this? (Let's say Eclipse for each installation)
How does starting a VM from a separate installation affect performance?
In general, it does not. Java applications (Minecraft, Open Office, LibreOffice, Eclipse, etc.) launched from the desktop run in distinct processes by virtue that each Java Virtual Machine (JVM) executing such applications are separate processes. However, it is also possible to run multiple applications in the same JVM; although it is unlikely in a normal desktop environment.
Without additional configurations, a Java application will run on a JVM from your default JRE or JDK installation. In the case of Minecraft, it will run in the JVM from the JRE installed with the new launcher, unless specifically changed in Launch Options using Advanced Settings. Eclipse will run in the default JVM unless configured differently in eclipse.ini.
What are the pros and cons of such an installation method?
In regards to Minecraft, the upside of a separate JRE installation are: 1) it ensures that a suitable JRE is available to run Minecraft; 2) eliminates potential problems dues to older or newer JRE versions; it is a game after all; and, 3) a different version can be installed without requiring changes to the user’s default JRE/JDK. There is no downside for Minecraft.
In regards to other use cases, the pros and cons can be as varied as the number of JREs installed. Case in point, we use current versions of Java 1.6, 1.7, 1.8, and even 1.9 for continuous integration and testing of various libraries and applications. The upside is that we can easily test a variety of environments. The downside is that it can become a configuration nightmare if one is not careful. For example, packaging a Java app under 1.8 and running its integration tests under 1.7. Fortunately, we keep an ample supply of aspirin around.

Is it necessary to use Docker in Java?

As Docker is a very hot tech currently, but I just wonder if it is necessary for Java? I list my reasons below, and any feedback is welcomed:
JVM just like a VM, which separate application from OS
Maven, manage dependencies
Spring Boot, support embed J2EE servelet containers like tomcat, all applications can be output as standard JAR file.
So, except you need to install JDK yourself, everything else is consistent and organized. I compare Java and Docker like below:
JAR -> Image
JVM -> VM
So, Docker really mean something for Java?
Docker is not necessary for Java. You can run a JVM on an operating system without worrying about Docker.
Docker is similar to a JVM in that they are both a level of virtualization, but it is probably not helpful to think of the virtualization provided by Docker as the same as the JVM. Docker is really a convenience tool for packaging together multiple applications/services into a container that is portable. It allows you to build the same virtual environment on multiple possibly different machines, or to destroy a virtual environment and restart it.
If you run a jar file with different versions of the JVM, you may get different results. For example, if the jar includes Java 8 functions but you try running on a Java 7 VM, you will encounter exceptions. The point of Docker is that you can control versions so this does not happen.
Depends. How much version support does your code has? How do you deploy your code? Do you use any databases and libraries other than java?
Docker is mostly for simplification of development process even when the one dev's machine differs from other. While java takes care of that by using jvm, think of a case when you are using functions that are on a newer java version, but your peer has an older java version on his machine. God forbid its your server.
Same applies when you are launching other services along with your java app. They will be databases and other services which will be versioned. Though internal libraries of java are themselves maintained by maven, they have no control over other services that you are dependent upon.
In short, no, Docker is not necessary for Java. Its not necessary for any language actually. It just creates consistency across multiple devs and production and other services, and hence the popularity.
You do not have to use Docker in Java but not for the reasons you gave.
Docker is not similar to a JVM! Docker is about having an isolated easily deployable environment that is configurable from outside, that can be started, stopped, and cloned easily.
Docker is similar to other virtualization technologies such as VirtualBox or VMWare but definitely not the JVM.
You can use Docker to select your OS, firewall settings, version of JVM and even more. You can use Docker to deploy 1 version or 1000 versions of your software. You can use Docker to give a fully-working environment to a customer or colleague.
JVMs do not do that.
Oh and there are security implications too.

Different java versions uses java web start on one computer

I have searched the forum for my question but have not found the precise info i need..
I have two web start applications that uses 2 different versions of java.. How is it possible for these to work on the same computer one app using version 1.6.0_30 and the other 1.8.
Inside the .jnlp file you will find attribute spec. Value assigned to it inform what Java Web Start is required to use the application.
Java is backword compatible so having only version 8 you will be able to run something dedicated to version 6.
Java allows to have multiple versions on single machine and also mange them.

Java - any ways to create standalone GUI apps for PC/Mac?

I'm interested are there any ways to create completely standalone desktop apps on JAVA? I mean to pack JAVA runtimes in distribution package, build apps for MAC/PC running *.jar files and get completely cross-platform software not depending on JAVA installed on target machine?
This is plainly not possible. You would need at least one executable wich would start on any platform you support to start setup/configuration. You may though use different wrappers for the specific OS to simplify installation of runtimes

Can I extend Jenkins with Jython/Python

Is it possible to write Jenkins plugins using Python (via Jython), and if so, where would I get started? I don't know Java (and don't have a real interest in learning it at the moment) so being able to use Python would be nice for me.
There's no docs on that. Frankly your problem with be you must understand how the interfaces and extensions map from java to jython to write it.
Here are links on writing Jenkins plugins
Let's you embed either Jython or Python scripts and run them from a plugin If all you nee to do is run a simple script, that be what you need.
If your goal is to execute Jython code within Jenkins, you may want to have a look at the Jython Plugin.
Starting version 1.6, you can actually install Jython packages (say if you have your own library you'd like to use), and it'll automatically sync up the packages across all Jenkins slaves.
Since Jython can produce Java classes I see no reason why this should not work.
Note that you will need to learn at least some things about Java (mostly the platform, not necessarily the language) in order to be able to write plugins for Jenkins.

Categories