Java error: Bad version number in .class file error when trying to run Cassandra on OS X

≡放荡痞女 提交于 2019-11-27 03:21:06

问题


I am trying to get Cassandra to work on OS X. When I run bin/cassandra, I get the following error:

~/apache-cassandra-incubating-0.4.1-src > bin/cassandra -f
Listening for transport dt_socket at address: 8888
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
 at java.lang.ClassLoader.defineClass1(Native Method)
 at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
 at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
 at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
 at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
 at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
 at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
 at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)

From what I could determine by searching, this error is related to incompatible versions of Java. However, as far as I can tell, I have the latest version of Java:

    ~/apache-cassandra-incubating-0.4.1-src > java -version
    java version "1.6.0_13"
    Java(TM) SE Runtime Environment (build 1.6.0_13-b03-211)
    Java HotSpot(TM) 64-Bit Server VM (build 11.3-b02-83, mixed mode)
    ~/apache-cassandra-incubating-0.4.1-src > javac -version
    javac 1.6.0_13
    ~/Downloads/apache-cassandra-incubating-0.4.1-src > echo $JAVA_HOME
    /System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home

Any ideas on what I'm doing wrong?


回答1:


The bad version number is almost always because you've compiled your java file to a class file with one version and are trying to run it with an earlier version.

You need to be certain the this "cassandra" is using the Java version you think it is. It's not necessarily using the same one you get when running java from the command prompt.




回答2:


If you using maven put in pom.xml, so this way it will compile by 1.5 even if u use 1.6

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
      <source>1.5</source>
      <target>1.5</target>
      <debug>true</debug>
    </configuration>
  </plugin>



回答3:


In cassandra/bin in the file cassandra.in.sh add the following 2 lines at the bottom of the file:

JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home
JAVA=/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Commands/java

This will be enough to get bin/cassandra to run. To get the other shell scripts to work with this you may need patch 590 and fix the other shell scripts to use JAVA_HOME and JAVA variables.



来源:https://stackoverflow.com/questions/1611312/java-error-bad-version-number-in-class-file-error-when-trying-to-run-cassandra

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!