Im running Eclipse Juno on Mac OSX 10.8.4, I tried to update my jdk to 1.7 when I run my Java App and I have this error:
Error occurred during initialization of VM
java/lang/NoClassDefFoundError: java/lang/invoke/MethodHandle
if I run on terminal
java -version
I get this
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
for updating this I set on Eclipse
Window - Preferences - Java - Installed JREs - Duplicate
JRE home: /Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
JRE name: Java SE 7 (MacOS X Default)
also changed compiler level
Window - Preferences - Java - Compiler - Compiler compilance level: 1.7
also added next lines to /Users/myUser/.bash_profile:
VA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_40.jdk/Contents/Home
export JAVA_HOME=$VA_HOME
export CLASSPATH=$VA_HOME
export PATH=$PATH:$JAVA_HOME/bin
but still getting same error
Any help I'll appreciate
in your launch configuration, check that the right JRE System Library is on the Classpath
Have you added JAVA_HOME to your PATH? Usually you get this problem due to a bad installation of the SDK. Try
javac -version
From the command line and see if this differs to
java -version
And produces the same NoClassDefFoundError as above.
The most probable reason of java/lang/NoClassDefFoundError is that you have a jar in your classpath which references another jar which is missing in classpath. The referencing classes won't be initialized.
Now for your case, you upgraded to 1.7 which would have added dependencies. Make sure your classpath now refers to jdk/jre 1.7
Related
its showing below details while checking 'java -version' in CMD
java version "11.0.15" 2022-04-19 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.15+8-LTS-149)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.15+8-LTS-149, mixed mode)
I am getting below response in Eclipse while using 'System.getProperty("java.version")'
Java Version is: 17.0.2
The CMD uses the PATH environment variable to search for executables (java.exe). The executable is searched in the directories listed in that variable, in the given order. The first one found, is the one that is executed.
Eclipse uses its own settings:
the JRE used to start Eclipse can be specified in the eclipse.ini file; if not specified there, the OS default will be used (usually the same as the CMD, see above);
the JRE used to execute an application inside Eclipse, is specified by the Run/Debug configurations (Run-Run Configurations.../Run-Debug Configurations...), the respective project properties (Project-Properties) and Eclipse preferences (Window-Preferences-Java-Installed JREs).
When I chose "Use Default Workspace JRE" inside Java Build Path->JRE System Library it is showing Java 11.0.15 in eclipse
Should java & javac version be same in the system?
as I am having java -version
java version "1.8.0_251" Java(TM) SE Runtime Environment (build
1.8.0_251-b08) Java HotSpot(TM) 64-Bit Server VM (build 25.251-b08, mixed mode)
and javac -version
javac 1.8.0_181
Is there any issue if it's not the same version?
Should java & javac version be same in the system?
Not really, you can have as many java version as you want on one system, as long as you know which version you use when compiling or running application. If you have multiple java version in your system, be aware which version you put on your PATH environment variable to avoid a miss.
Your problem should be caused by multiple entry in your PATH environment variable that refering to java installation directory that has different version (note, java can be found in JDK and JRE installation, while javac can only be found in JDK installation).
Is there any issue if it's not the same version?
There should be no issue, as long as you don't use features that can only be found on the java version you use when compiling the program. In your case, the different is in build version, it's okay.
I am getiing java versions different with java command and javac command
java -version
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) Client VM (build 25.0-b70, mixed mode, sharing)
javac -version
javac -version
javac 1.6.0_18
where java
C:\Windows\System32\java.exe
C:\Program Files\Java\jdk1.6.0_18\bin\java.exe
path is set to 1.6 but it is picking 1.8
suggest me how to get this resolved.
This is cause by the extremely annoying habit of the Java installer to copy java.exe andjavaw.exe to C:\Windows\System32\java.exe when you choose to install the "public jre" (but because that's the JRE, of course no javac.exe is copied).
And because System32 comes early in the PATH java.exe from there will be used (and before the regular JDK installation will no be searched for java.exe). But as there is no javac.exe in the JRE, that in turn is used from your JDK.
The public JRE is only needed for the browser Java plugin. In 2014 I consider the Java plugin to be dead and (I think) Oracle should change the JDK installer to not install that automatically.
Actually I consider this behaviour a bug to be honest. No installer should copy files to system32
I have legacy code that uses jruby that needs java 1.6
My current setup is:
$ java -version
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)
08:42:11 mdurrant C02MH2DQFD58 /Users/mdurrant
$ ruby --version
jruby 1.7.4 (1.9.3p392) 2013-05-16 2390d3b on
Java HotSpot(TM) 64-Bit Server VM 1.6.0_65-b14-462-11M4609 [darwin-x86_64]
Now I want to use eclipse and the latest version requires the jdk version 1.7
How can I add that and then have them co-exist?
I'm worried that this will effectively upgrade my existing 1.6 to 1.7 (the newer gives me lots of memory issues in my apps - yeah that's as backwards as it sounds, the newer version being worse at memory management - probably due to how our apps are built).
Install as a default JRE from Java Build Path -> JRE System
Library -> Installed JRES -> Add ...
or
You can specify JDK version for usage with Eclipse in eclipse.ini. This will resolve problem with starting Eclipse.
-vm // Add this configuration before -vmargs.
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home/bin/java
or You can install jenv
jenv is for a equivalent of rbenv, but for Java environnement. It allow to easily switch between several JDKs installations (already presents), and configure which one to use per project.
Install or specify as a default JRE in eclipse from Java Build Path -> JRE System Library -> Installed JRES -> Add .
otherwise specify the default Jdk file in eclipse.ini configuration file
I have set the Module SDK to 1.6
I have also set the Project SDK to 1.6
and I also change Java compiler options from setting to use java 6
but still it is using java 7 to compile. When I compile or run it gives following error
Using javac 1.7.0_11 to compile java sources
java: Errors occurred while compiling module 'SSLJava6'
Compilation completed with 1 error and 0 warnings in 1 sec
1 error
0 warnings
java: javacTask: source release 1.7 requires target release 1.7
Has anyone faced such problem before? What must be done?
Output of java -version
[aniket#localhost jndiProperties]$ java -version
java version "1.6.0_30"
Java(TM) SE Runtime Environment (build 1.6.0_30-b12)
Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)
and my JAVA_HOME is also set to same.
Interesting.
Questions:
Check that c:\Users\$user\.IntelliJIdea12\config\options\jdk.table.xml has a reference to JDK6 only. This is what the file looks like for me:If there is a reference to a JDK 7 in there then delete the corresponding <jdk> element and restart Intellij.
I know that you have confirmed the java and javac path. Confirm the javac being used by writing a simple HelloWorld.java in a brand new Intellij project. If in the new project javac6 is used, then it's an issue with the old project configuration.
If there is a public JRE 7 lurking about, try un-installing it temporarily. After un-installation check that there is no cruft left behind in the Windows registry at HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment
Check whether the build fails if you rename the JDK7 home dir. If so, try symlinking the JDK7 dir to point to the Java6 installation dir. In the windows world the following will work to do the symlink : mklink /J c:\Java7Home c:\ExistingJava6Home
Try setting your IDEA_JDK_64 environment variable to point to your java SDK you want intelliJ to use for example 'D:\Programs\Java\jdk1.9'.
I encountered this issue when installing the new java 9 early access jdk and trying to run it on intelliJ 15.
This fixed it on IntelliJ 16 EAP versions.