I just started to learn Java using Thinking in Java book, and have some troubles using ant.
I'm using Ubuntu 12.04, and have openjdk 7 java installed. I also setup the CLASSPATH to be the code folder
When I run ant in code folder, this is the output:
Exception in thread "main" java.lang.RuntimeException: JDK 1.4.1 or higher is required to run the examples in this book.
[CheckVersion] at com.bruceeckel.tools.CheckVersion.main(Unknown Source)
However when I run java -version, this is the output:
java version "1.6.0_27"
OpenJDK Runtime Environment (IcedTea6 1.12.5) (6b27-1.12.5-0ubuntu0.12.04.1)
OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)
How to setup ant and classpath correctly?
P/S: Thanks everyone for the help!!! I figured out why it fails to check the version.
The testing condition is "if(minor < '4' || point < '1')" in CheckVersion.java. Yet my version is 1.6.024, eventhough 6>4 but 0<1 that's why it failed. I guess we need to rewrite the testing condition!
Try setting your JAVA_HOME environment variable to the install directory of your 1.6 JDK.
When you type "java -version", the command shell is using the first java executable it finds in your PATH. Ant probably looks for the java executable in the "bin" sub-directory of your JAVA_HOME directory.
To find the location of your java executable, type the following:
which java
and let's say you got the following output:
/usr/local/java1.6/bin/java
You would then set your JAVA_HOME variable to /usr/local/java1.6. Assuming a Bourne or Bash shell, the syntax for that would be
export JAVA_HOME=/usr/local/java1.6
Related
In my university we are learning about writing RMI applications. When I first tried running the example application in Eclipse 2019-03 I ran into the error:
java.lang.UnsupportedClassVersionError
I successfully ran other projects (non RMI) without any problems.
When I run
java -version
I get:
openjdk version "11.0.3" 2019-04-16
OpenJDK Runtime Environment (build 11.0.3+7-Ubuntu-1ubuntu218.04.1)
OpenJDK 64-Bit Server VM (build 11.0.3+7-Ubuntu-1ubuntu218.04.1, mixed mode, sharing)
and
javac -version
I get:
javac 11.0.3
I have Java 8 and 11 installed on my system running Ubuntu 18.04.
When looking for a solution to the problem, I found this question:
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version
Changing the settings of the compiler compliace level in Eclipse to 1.8 did AND changing the project specific Settings helped me and I was able to finally run the Application without any errors. This solution does not satisfy me though.
When I run
update-alternatives --config java
and
update-alternatives --config javac
in both cases openjdk11 is selected.
I do not understand, why I get the error if i dont change the compiler settings.
One of the answers suggested it is a wrongly set $JAVA_HOME varable. When I run:
jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));'
It indeed gives me the answer
/usr/lib/jvm/java-8-openjdk-amd64/jre
I tried following this guide to change it to openjdk11:
https://askubuntu.com/questions/175514/how-to-set-java-home-for-java
When I now run
echo $JAVA_HOME
I get:
/usr/lib/jvm/java-11-openjdk-amd64
but when I run
jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));'
again the answer is still the same.
I want to be able to use my openjdk 11 to compile and run the code without changing the compiler settings in Eclipse. Anybody had the same problem and a tip for me?
Thank you in advance!
The full error is the following:
java.lang.UnsupportedClassVersionError: chapter6/Counter has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
The /etc/alternatives is ignored when running inside Eclipse. Instead, you have a separate definition of which JDK/JRE to use. This can be set globally in the Eclipse Preferences, one-by-one in the Project Properties, or even at the Debug/Run configuration (in order to test your application in multiple java versions).
I get an error trying to install Eclipse 4.7 (Oxygen) Oracle Corporation using the installer program, eclipse-inst-win64.exe Am I missing a system variable? Am I missing a prerequisite? This computer is locked down pretty tight. However I am installing by running as an administer.
First I installed the Oracle JDK 8.162 64-bit - No problems
Then I ran the eclipse-inst-win64.exe installer and quickly got the following error:
The Eclipse Installer executable launcher was unable to locate its companion shared library.
I thought this could be just that the program did not know where the JDK was installed. The JDK installer does not set any environment variables except for adding the path to the JDK to the PATH variable. So I searched StackOverflow for a list of JDK variables to add. I added the following new system variables:
CLASSPATH = .;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib
JAVA_HOME = C:\Program Files\Java\jdk1.8.0_162
JAVA_TOOL_OPTIONS = -Dfile.encoding="UTF-8"
JDK_HOME = %JAVA_HOME%
JRE_HOME = %JAVA_HOME%\jre
I modified the Path variable to put the bin directory first:
PATH = %JAVA_HOME%\bin;C:\windows\system32;C:\windows… rest of the existing path variable
I ran the eclipse-inst-win64.exe installer again and got the same error:
I rebooted but still got this error.
I tried to "run as administrator" but got the same error.
Some people suggest that the path can get too long with the default installation directory so I tried installing the JDK in C:\JDK\ but still got the same problem.
Java seems to be installed properly:
H:>java -version
java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)
I still assume that I made a mistake with my system variables or my JDK installation.
I assumed the "companion shared library" was inside the JDK installation. I extracted the installation files to another directory (C:\eclipse) and then it ran. The "companion shared library" must have been inside the zipped installer. I fixated on the idea that the problem had to be a failure to connect to the JDK that I did not consider any other possibilities. It is installed now.
I have trouble when trying to open my jar files with the following command:
java -jar software.jar
They load until a certain point and then nothing happens.
I deinstalled default-jdk and OpenJDK with synaptic and re-installed it with apt-get, but nothing changed. I had a similar problem one month ago and solved it (apparently only temporarly) by deleting the package gcj-5-jre-lib (5.4.0-6ubuntu1~16.04.4) (Java runtime library for use with gcj (jar files))
The following outputs will help:
java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-8u131-b11-2ubuntu1.16.04.3-b11)
OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)
javac -version
1.8.0_131
My variables $JAVA_HOME and $JRE_HOME were correctly added to my $PATH.
I'm on Ubuntu 16.04
EDIT
Here is an example of what I get when I try to start PhyDE.jar
java -jar PhyDE.jar
Welcome to PhyDE 0.9971!
Reading preferences.
Creating PhyDE-Application window
Checking for updates...
You are using the latest version of PhyDE
Done with checking for updates
When checking the core use with the command top I see that the process is active, but the user interface does not open as it usually does. I am located in the folder where the jar file is, and same happens with other jar files.
I started off with CentOS and OpenJDK 1.7
# java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
In order to run a specific application, I want to use Oracle's Java 1.6, provided from an RPM.
I copied the Oracle binary to a specific new directory:
# pwd
/oracleJava/jdk-6u45-linux-x64-rpm
I extracted the binary and it gave me the following files:
# ls
jdk-6u45-linux-amd64.rpm
sun-javadb-core-10.6.2-1.1.i386.rpm sun-javadb-javadoc-10.6.2-1.1.i386.rpm
sun-javadb-client-10.6.2-1.1.i386.rpm sun-javadb-demo-10.6.2-1.1.i386.rpm
sun-javadb-common-10.6.2-1.1.i386.rpm sun-javadb-docs-10.6.2-1.1.i386.rpm
I installed the RPM and the rpm utility believes that it installed properly:
rpm -q jdk
jdk-1.6.0_45-fcs.x86_64
# rpm -Uvh ./*.rpm
Preparing... ########################################### [100%]
package jdk-2000:1.6.0_45-fcs.x86_64 is already installed
# rpm -Uvh sun-javadb-*.rpm
[I omit the feedback because it generates a formatting error]
#
However, the Java version just shows 1.7
# java -version
java version "1.7.0_25"
OpenJDK Runtime Environment (rhel-2.3.10.4.el6_4-x86_64)
OpenJDK 64-Bit Server VM (build 23.7-b01, mixed mode)
In other words, I was expecting the Oracle files to give me some new /java directory somewhere, with a new java executable that would return a different answer for "java -version"
I need that new directory so that I can set JAVA_HOME and use the 1.6 version of Java.
Helpful suggestions would be greatly appreciated. Thanks in advance.
The Oracle JDK RPMs are horrible.
They do not register with the alternatives system.
They do not Provide (in RPM terms) "java"
They have messed up their RPM 'version string' and rely on Epoch (...)
All versions of the JDK (i.e. 1.6 vs 1.7) have the same Epoch
In order to quickly remedy your problem you can run the following:
/usr/sbin/alternatives --install /usr/bin/java java /usr/java/default/bin/java 20000
It will register and prefer the Oracle java installation as an alternative. OpenJDK has weight 16000; here we register with 20000. Once you've run this command you can switch between java versions by using the (already mentioned) alternatives --config java command.
As for a less quick fix you can use my virtual java package. It's quite possibly not perfect (I'm open for improvements ;) ), but it Provides java (making my apache-tomcat package happy) and registers with the alternatives system. This virtual package simply depends on jdk...you can find it here: https://github.com/keystep/virtual-java-rpm
Run the following command to see if your JVM is getting listed.
sudo update-alternatives --config java
If your JVM gets listed select it.
The problem is that Oracle's RPMs are (wilfully IMO!) ignorant of the "alternatives" system.
Instead, they install stuff in a non-standard place (/usr/java) and then expect the user / system administrator to mess with the PATH variable ... by hand.
It is a nuisance!
So what has probably happened in your case is that your JDK / JRE has been installed in a subdirectory of /usr/java ... but since you haven't added the relevant bin subdirectory to the front of your PATH you are still picking up the OpenJDK tools via the java command name.
You can fix this after the fact by using "alternatives" to configure and then select the Oracle commands. But it is messy, especially if you want the JDK tools as well. (There are a lot of them!)
Please check that whether your JAVA_HOME points to JDK 6 using echo $JAVA_HOME. In order change your JAVA_VERSION to Java 6, you need to point to the Java development KIT 6. You also need to add the bin directory to the $PATH variable. Please ensure that JDK6 bin directory comes in the $PATH prior to other JDK bin,if any. You can check the version of your Java in the environment by command java -version.The other answer by learningloop is very perfect to switch between different Java configurations
Try to the following method
delete OpenJDK folder from
/usr/lib/jvm
I had same problem and got solution through this method
Hi everybody.
The problem: elcipse-3.5.0 (Galileo) spits with an error when I try to launch it by clicking its launcher. The curse sound like this:
A Java Runtime Environment (JRE) or
Java Development Kit (JDK) must be
available in order to run Eclipse. No
Java virtual machine was found after
searching the following locations:
/home/emanemos/bin/eclipses/eclipse-3.5.0/jre/bin/java
java in your current PATH
However, everything goes smoothly when eclipse is started from console.
Before installing eclipse I've installed jdk1.6.0_16. I also created the $JAVA_HOME variable and changed my $PATH:
$ echo $JAVA_HOME
/usr/lib/java/jdk1.6.0_16
$ echo $PATH
/home/emanemos/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/java/jdk1.6.0_16/jre/bin
So that, my terminal got to know what java is:
$ java -version java version
"1.6.0_16" Java(TM) SE Runtime
Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build
14.2-b01, mixed mode, sharing)
Then a folder eclipse was extracted from .tar.gz package under the directory ~/bin/eclipses. I changed the folder's name eclipse to eclipse-3.5.0 and changed $PATH again:
$ echo $PATH
/home/emanemos/bin/eclipses/eclipse-3.5.0:/home/emanemos/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/java/jdk1.6.0_16/jre/bin
From this moment I was blessed to launch eclipse from console by the command eclipse.
However, I feel desperate about using the eclipse's application launcher.
Thanks in advance. I would be grateful for any help.
The message says "No Java virtual machine was found after searching the following locations: /Applications/eclipse/Eclipse.app/Contents/MacOS/jre/bin/"
I have solved it creating the folder /Applications/eclipse/Eclipse.app/Contents/MacOS/jre/bin and linking to the command at /usr/bin/java:
ln -s /usr/bin/java /Applications/eclipse/Eclipse.app/Contents/MacOS/jre/bin/java
Add this to eclipse.ini:-
-vm
$Java_home/jdk1.5.0_14/bin/javaw.exe
I could be off, but it looks to me that you don't have JAVA in your path. If you notice, you had to add it via the echo command. However, that only stays for that session of the terminal. You don't permanently affect the system. (I believe that's why you can launch from the terminal, but not via the launcher.)
Do you have the Java JRE actually installed on your system? If not, I would recommend doing that as that should do all the setup that you would need, then try running Eclipse again.
Edit: I noticed you said that you did install the 1.6 JDK. This should have fixed your problem. If Java is not in your path when you first open up your terminal, then that (I believe) is your real problem and you may need to do a reinstall or troubleshoot there.
(Making a big assumption that you're on Linux using X)
If you've installed the Java JRE without logging out and back in to the X session, the environment the session is in won't contain the $JAVA_HOME variable. It may just be a case of logging out and back in in order to get a new X session.
If you want to keep the same session running, you could try it out by pressing Ctrl+Alt+F9 to start another GUI session.
Fazil Baghirzade i solve the this problem
A Java Runtime Environment (JRE) or Java Development Kit (JDK) must be available in order to run Eclipse. No Java virtual machine was found after searching the following locations:
c:\Program Files\Eclipse\jre\bin\javaw.exe 'javaw.exe' in your current path
go to the "C:\Program Files\Java\jdk1.6.0_39" in this folder have "jre" folder copy it and paste the eclipse folder
thats all!!!