96

My development team recently was forced over to a remote development environment where we do not have full access to the servers. Before the change over we had a JAR that was running fine on Java 1.7 x64 along with JRE 7. When we moved over to the new server our JAR was running alright, but then one of the server admins "updated" our Java to an older version and uninstalled the one we were using. Don't ask me why, I don't know. I re-installed Java 1.7 and uninstalled 1.6 along with the JREs.

The following problem occurs at runtime, there are no build errors:

Registry key 'Software\JavaSoft\Java Runtime Environment\CurrentVersion'
has value '1.7', but '1.6' is required.
Error: could not find java.dll
Error: could not find Java SE Runtime Environment.

I've run the same JAR on my laptop with no issues. Both the server and my laptop have JDK 1.7 and JRE 7 in the respective %HOME% variables and system PATH. I've even reinstalled JRE 6 and placed it later in the system environment PATH variables with the same result.

I have also changed the registry back to look at 1.6 and it results in the following, which I looked up and it appears to be from having multiple Javas installed (leading back to my original problem):

Exception in thread "main" java.lang.UnsupportedClassVersionError: ... :
Unsupported major.minor version 51.0

I would appreciate any insight you all have as I have been looking over various forums but nothing seems to have exactly my problem. Also, this has happen on another server we are using as well. Thanks!

Update: No luck with recompiling the JAR to either 1.6 or 1.7 and matching the JDK. Also, why in the world would a newer version of Java break an older compiled version?

notsodev
  • 1,447
  • 2
  • 13
  • 20

10 Answers10

160

This happens when you somehow confused java itself. You are trying to run a java 6 VM where it found a JRE 7. It might show this problem even if you type in the command line just java or java -version in a misconfigured environment. The JAR is not the problem, except in the very unlikely case where the code in JAR is looking in the Windows Registry for that (which probably is not your case).

In my case, I had the java.exe, javaw.exe and javaws.exe from Java 6 in the Windows/System32 folder (don't know how it got to be there). The rest of the JDK and JRE where found in the PATH inside C:\Java\jdk_1.7.0\bin. Oops!

  • 64
    Faced same issue but with Java 8 after uninstalling same. Fixed issue by deleting java.exe, javaw.exe and javaws.exe present in Windows/System32. Really strange coz even i don't know how it got there. – C Deepak Dec 25 '13 at 10:02
  • 2
    Thanks for notice, it helps. JDK 1.7 vs JDK 1.8 in my case. – daoway Oct 01 '14 at 11:04
  • 7
    For x86 People!! I originally install the 1.8 jre couple months ago and wanted 1.8 sdk. `java.exe`, `javaw.exe`, and `javaws.exe` is stored under `Windows/SysWOW64`. Also for some reason when I installed the 1.8 sdk it installed `java.exe`, `javaw.exe`, and `javaws.exe` under `C:/ProgramData/Oracle/Java/javapath`. Don't know why, but I deleted them as well and `java -version` still works. – Luminous Nov 11 '14 at 00:23
  • 1
    System32 was the key for me. I've made sure that javapath has the right version and my environment variables are set properly... nothing worked until I fixed that System32 deal. It all has to be on the same page. – B.K. Dec 14 '14 at 04:48
  • 2
    deleting java.exe, javaw.exe and javaws.exe present in indows/System32 fixes the issue for me. Thanks @C Deepak – Tahir Jilani Jan 28 '15 at 10:57
  • 1
    In a generic case, typing `where java` returns the suspicious entries (anything other than the place you actually installed the JRE). If you, like me, were unable to find the java.exe through Explorer, open up `cmd` **in administrator mode** and type `del PATH_TO_JAVA/java.exe` – Sharadh Mar 06 '15 at 08:46
  • 1
    @Victor I'm no longer in this environment, and while this did not help me at the time, I'm glad so many others were helped by my question and your answer! – notsodev Mar 06 '15 at 14:55
  • 1
    @notsodev That is really nice. I myself found your question for having this problem too, and after being able to identify the cause and solve it (by deleting the wrong files on system32), I decided to contribute with feedback and posted this answer. I did not know at the time that this problem was so recurrent to affect so many people! :) – Victor Stafusa - BozoNaCadeia Mar 06 '15 at 15:10
59

Just had the similar error when installing java 8 (jdk & jre) on a system already running Java 7.

Error: Registry key 'Software\JavaSoft\Java Runtime

Environment'\CurrentVersion' has value '1.8', but '1.7' is required.

Error: could not find java.dll Error: Could not find Java SE Runtime Environment.

My environment was set up correctly (Path & java_home correctly defined), but the problem arises from the way pre-8 Java installers worked, which is that they used to copy the three executables (java.exe, javaw.exe & javaws.exe) to the Windows system directory. These remain unless overwritten by a new pre-8 installation.

However the Java 8 installer instead creates symbolic links in a new directory, C:\ProgramData\Oracle\Java\javapath, pointing to the actual JRE 8 location.

This means that you'll actually run the old 7 exes but use the new 8 DLLs.

So, the solution is simply to delete the 3 Java exes, as above, from the windows system directory.

If you are running 32-bit Java on a 64-bit Windows, the exes would be in Windows\SysWOW64, otherwise in Windows\System32.

Community
  • 1
  • 1
Jool
  • 1,706
  • 16
  • 14
28

I've deleted java files at windows/system32 and I also have removed c:\ProgramData\Oracle\Java\javapath from the PATH variable, because there was 3 symlinks to java 1.8 files.

I had JDK 1.7 in the %JAVA_HOME% variable and java1.7/bin in the PATH.

PS1: My problem was between Java 1.7 and Java 1.8.

PS2: I can't add this as a comment to Victor's answer because I haven't enough points.

  • 3
    Problem: I faced 1.7 & 1.8 problem while trying to use sencha cmd. Solution: I added jdk1.7/bin path in %PATH% environment variable & removed java files (java.exe, javaw.exe, javaws.exe) from c:/windows/system32 directory. The problem got resolved :) – saurabh Nov 07 '14 at 03:11
  • 3
    the whole f*** problem was the X:\Windows\SysWOW64 and X:\Windows\System32 java*.exe files.. once removed all got working again.. – thiagoh Jan 31 '15 at 03:43
17

In the START menu type "regedit" to open the Registry editor

Go to "HKEY_LOCAL_MACHINE" on the left-hand side registry explorer/tree menu

Click "SOFTWARE" within the "HKEY_LOCAL_MACHINE" registries

Click "JavaSoft" within the "SOFTWARE" registries

Click "Java Runtime Environment" within the "JavaSoft" list of registries here you can see different versions of installed java

Click "Java Runtime Environment"- On right hand side you will get 4-5 rows . Please select "CurrentVersion" and right Click( select modify option) Change version to "1.7"

Now the magic has been completed

satender
  • 1,199
  • 13
  • 12
4

I don't know if anyone is still following this thread, but I recently had this issue when I tried to launch ActiveMQ 5.10 as a Windows service.

I didn't have a JAVA_HOME path set. I had Java 6 and Java 7 installed, but the default version was v7. (ie if I opened a command window and types "java -version").

This is where the clue was - "java -version" returned "Java HotSpot(TM) 64-Bit Server VM (build 23.1-b03, mixed mode)" but I was had installed the Win32 service...

It turns out that if you use the Win32 wrapper on a 64-bit machine it somehow decides to use a different version of Java...

So my fix was to uninstall the 32-bit version of the wrapper and install the 64-bit version. aversion on my machine; just habit I guess... But luckily I resolved the issue eventually...

James Joyce
  • 1,694
  • 18
  • 20
  • 1
    You can encounter this problem if you have both the 32 and 64 bit versions of Java installed, and an automatic (or in my case forced corporate) update only updates 1 of them. Uninstalling all instances of Java and re-installing both 32 and 64 bit will resolve. – DannyMeister Nov 06 '14 at 16:15
0

For my Win7

Paradox was in being java.exe and javaw.exe in System32 folder. Opening that folder I couldn't see them but using search in Start menu I get links to those files, removed them. Next searsh gave me links to files from JAVA_HOME

magic )

-1

Change to directory with correct java.exe i.e. go to the required JDK version java.exe

cd C:/Program Files/Java/jdk1.7.0_25/bin

Run the java.exe from this directory, it has precedence over registry and $PATH settings.

java -jar C:/installed/selenium-server-standalone-2.53.0.jar 
Barun
  • 1,520
  • 2
  • 12
  • 18
-2

I solved this problem by uninstalling Java 1.8

Iman Marashi
  • 5,593
  • 38
  • 51
-3

The jar was compiled to be 1.6 compliant. That is why you get this error. Two resolutions:
1) Use Java 1.6

OR

2) Recompile the jar to be compliant for your environment 1.7

Woot4Moo
  • 23,987
  • 16
  • 94
  • 151
  • I have actually done both, but let me back up a bit. The JAR is actually being run through a C# GUI. The JAR itself runs through the command line, but not through the GUI. I am thinking it could possibly be another JAR within the the JAR I am running (pertaining to running the GUI). Could this then be the case? That a nested JAR file was compiled to 1.6? – notsodev Mar 07 '13 at 21:39
  • This sounds implausible. Java versions are downwards compatible; code compiled for / on JDK 6 will work on Java 7 without recompiling or modifications. – Jesper Mar 08 '13 at 19:26
  • @Jesper i may be confusing this with a similar issue I see in Eclipse often. – Woot4Moo Mar 08 '13 at 19:42
  • 1
    @Jesper that is why this all doesn't make sense to me. Everything I find is related to a new version of a JAR running on an old Java like 1.6 with a 1.5 JRE. But this problem seems backwards. – notsodev Mar 11 '13 at 14:49
-3

Using regedit, remove the entries corresponding to java 7. It will work.

Unihedron
  • 10,902
  • 13
  • 62
  • 72
Olive
  • 1