I built my NetBeans web project with Java 1.5 successfully, however; my linux server supports / uses Java 1.4 and Java 1.5 (as well as JBoss 4.0.2).
When I check the version of my project ( java -version ) it says that the current version is Java 1.4.2. However, I don't want to change the "JAVA_HOME" setting on the server because other projects need to use this version.
I want my project to use Java 1.5 from the server...
An idea as to how I should go about doing this? Is there a configuration that I can change?
I have this error:
java.lang.UnsoupportedClassVersionError: bad Version in .class file
You need Java 1.5 version installed in your Linux server.
Next, run the following set of commands in your terminal/command prompt:
JAVA_HOME="{fix-me}"
export JAVA_HOME
export PATH = $JAVA_HOME/bin:$PATH
In the place holder {fix-me} specify the path of Java 5 that is installed in the Linux machine.
This would only temporarily set the Java version to 5 until the terminal/command prompt session is alive. So you need not worry about disturbing other projects.
Related
I have JDK 1.8 installed in my Linux server.
I want to deploy my Spring boot application that runs on JDK 11 to Linux server.
I cannot upgrade JDK version of my Linux server since there are other application running on the same Linux server and i don't want to disturb them.
For this reason i have Zipped JDK 11, copied it to Linux Server in a folder specific to my application(same place where my spring boot application jar resides) and un-zipped it.
I tried to start my application with the following command but it still runs JDK 1.8 by default and throws exception
java -cp test-api-0.0.1-SNAPSHOT.jar com.test.api.TestAPIApplication
How can i modify the above Linux command to make my application run on JDK 11
I cannot modify java path since it will affect other applications on same Linux server.
Sorry, but you can't:
You can't tweak the Java version via the -cp option.
You can't run a Java version that is not installed.
If you want to run a SpringBoot application that has dependencies on Java 11 (or later) features or APIs, then you must install Java 11 (or later).
The Java 11 libraries are compiled with to Java 11 classfile format. A Java 8 JVM won't understand them. Furthermore, the libraries (most likely) depend on native code methods (and other things) that are only available in a Java 11 (or later) java executable. This means that your idea of not installing Java 11 is technically infeasible.
But what you can do is install Java 11 alongside Java 8 on your server, and then select the version of Java you use either by using an absolute pathname for the java command or setting the PATH environment variable appropriately.
(On a typical Linux system, the package names for Java 8 and Java 11 are different. So there should be no difficulty installing either versions, or having both versions installed at the same time. Likewise, the Oracle Java installers install into different Java versions into different directories.)
(Likewise, environment variable settings are NOT shared in Linux. So you can set them differently for different applications. If you make the PATH or JAVA_HOME or whatever changes in the appropriate places, your new Java 11 application won't interfere with existing Java 8 apps. It is just "basic shell stuff".)
i have a java program that must run on an as400, running it from qshel run jre 1.6, but my dependencies require jre 1.8 is it possible to start that program with portable 1.8 jre?
as is also done on Windows and Linux with the .bat and .sh files!
can you tell me the commands to customize the (java home) without moving the 1.6 installed?
Traditionally, the only JVMs available for the IBM i platform come from IBM. These are available through various options of the 5770-JV1 product. Versions up to 1.8 are available for IBM i 7.1 and up (perhaps earlier, but I haven't gone digging) You can find the available JVM options at https://www.ibm.com/support/pages/node/1117869
To use a Java 1.8 64-bit VM from QSH, you could do eg.
JAVA_HOME=/QOpenSys/QIBM/ProdData/JavaVM/jdk80/64bit
export JAVA_HOME
java -jar ...
Your challenge is a very common task in legacy systems.
This worked for me:
Put your portable jre.zip close to your java program.
Unzip it
Create a JAVA_HOME just for this execution:
export JAVA_HOME=/home/mydownloads/jre
export PATH=${PATH}:$JAVA_HOME/bin
Try with java -version
Execute your java program: java -jar myapp.jar
You could add this steps to yous bash scripts.
I am working on an android application using Kotlin. I am running a kotlin linter through command line ./gradlew klint.
But it gives me an error:
Gradle 4.4 requires Java 7 or later to run. You are currently using Java 6.
When I check the project structure, I am using the embedded JDK.
I also updated android studio to latest version. I do not know how to update the embedded JDK to latest version.
java version
"1.6.0_65" Java(TM) SE Runtime Environment (build 1.6.0_65-b14-468) Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-468, mixed mode)
which java - /usr/bin/java
echo $PATH - /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/username/Library/Android/sdk/platform-tools
echo $JAVA_HOME - empty
A copy of the latest OpenJDK comes bundled with Android Studio 2.2 and higher, and this is the JDK version we recommend you use for your Android projects.
https://developer.android.com/studio/intro/studio-config.html#jdk
This however, is only for building your apps within Android Studio, not from the terminal with gradlew, otherwise, it'll use whatever is on your OS's $PATH variable.
In order to use the embedded JDK, you at least need to set JAVA_HOME, for example on Linux/Mac,
$ export JAVA_HOME=/path/to/AndroidStudio/jdk # TODO: Find this
$ ./gradlew
My recommendation, however, is to use the mechanism for your OS for installing Java.
For easy Java library management (on Linux & Mac), you can try using sdkman
gradle.properties can be updated to point to the embedded JDK that comes with Android Studio in Mac OS:
org.gradle.java.home=/Applications/Android Studio.app/Contents/jre/jdk/Contents/Home
The issue is resolved by adding :
/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin
at the start of the PATH variable . What i have found is that: There are three java locations.
Java that comes with mac (/usr/bin/java)
Java downloaded from oracle . ( /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin)
Java embedded with Android Studio (/Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/bin/)
In my case the gradlew was always using the java from MAC (point number 1).
So when i added the " java dowloaded from oracle (point 2)" at the start of path variable it started using the one from oracle and my gradlew command ran.
So I'm trying to get the latest version of Java. When I run:
java -version
I get:
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
When I run:
javac -version
I get:
javac 1.6.0_65
Now I've just downloaded and installed JDK 8. When I go into System Preferences --> Java --> Update, I see:
Your system has the recommended vesion of Java.
Java 8 Update 05.
I guess I have a few questions:
1) Don't I want the JDK and my version of Java to match up?
2) Why does my Java Control Panel claim I have Java 8, but my work in the terminal (when checking my Java version) says otherwise?
Thanks for the help,
Mariogs
The probably "simple" answer is you have two versions of java installed. On the command line you currently use 1.6. Thus the old one is active. In system preferences you see the version of java 8.
Windows:
You can change the version of the command line to java 8. Set PATH environment variable and JAVA_HOME or via windows preferences. I recommend the first one.
Mac: /usr/libexec/java_home is the starting point for switching java versions on the command line. Check out this post to understand how to handle different java versions on the Mac. IMHO this answer is a good solution.
The Java Platform offers both the JRE and the JDK in order for users to run Java programs. The JRE stands for the Java Runtime Environment, and the JDK stands for the Java Development Kit.
The JDK is meant for Java developers - that is, those who build applications/write programs in Java. It contains tools that are needed for Java coding, including -javac to compile programs.
The JRE is meant for regular users - those who only need to run Java programs on their computer and are not interested in development.
The reason for the discrepancy in your case is because you're looking at the JRE and JDK and trying to compare the two. The current JDK that you have is Java 8, whereas the current JRE that you have is 1.6.0_65. It is problematic that your JRE version does not match your JDK version, but without your PATH variable or other information about your install, we can't help you fix your installation.
1) Yes, if you use the JDK at all, you want the JRE (runtime environment) to come from the JDK (development environment) (a JDK necessarily includes a JRE).
2) Likely your path variable is set so that you invoke Java from your Java 6 installation; you need to find the equivalent for your Java 8 installation and set the path for that. Without information about your operating system, we can't help you do that.
We should know the reason for this
Our OS comes with a predefined (built-in)set of tools and utilities. When we try to execute the command e.g. cls in the Windows command line then it is already present in system path variable and os will refer the corresponding binary of cls to execute the command.
However, when we install any third party tool/software then path variable is not updated accordingly.
When we install different versions of java on your system then installations go to different directories. E.g. JDK installation directory for Windows will be
C:\Program Files\Java\jdk1.8.0_161
Similarly, JRE installation directory for Windows will be JDK installation directory for Windows will be
C:\Program Files\Java\jre1.8.0_161
We need to update the path variable of OS to point to the appropriate directory. If we set the path of JDK then it will execute a binary from JDK bin directory.
Solution
we need to update JDK or JRE version specific directory location into PATH Environment variable.
Let me see if I can clear it up for you.
1)Yes, arguably you nearly want this to be true.
2)It could be few things, but most likely that a previous instillation was not properly removed. So one gets called instead of the other.
I am using jre 6 now. Earlier, I was using javasdk1.4 but as I searched in Internet, found that enum is supported in 1.5 or higher version. So, I first updated jre to latest version and then now how to update j2sdk1.4 .
When I am using echo %PATH%
path showed is "C:\Program Files\Java\jre7\bin"
But I can't set path to this location as 'javac' here is not recognizable..
My enum code i am not posting but is verified that it is correct.. Here, I am facing problem of setting path and updating j2sdk 1.4 even after jre updated to latest Version.
Note: I want to set path using command-prompt and Path command not using environment Variable.
I am using windows Xp
javac is not included in the JRE, it's just a runtime environment (Java Runtime Environment) used to run Java applications, nothing more.
Download a JDK (Java Development Kit) instead.