-2

I have created a basic file browser in Java. I exported it to a runnable Jar file in eclipse. It works fine on my windows machine, however when I try to run it on my Ubuntu machine from the command line I get the following error:

Exception in thread "main" java.lang.UnsupportedClassVersionError: Main : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
Could not find the main class: Main. Program will exit.

The jar file is marked as executable, I have tried running it by double clicking on it, and right click > open with openjdk Java 6 runtime

EDIT: I tried with Java 7, same error comes up.

TheRyan722
  • 1,029
  • 13
  • 37
  • 1
    Please try searching for an answer before you ask. As you can see, this problem is well-known ... and your question has been asked and answered many times before. – Stephen C Aug 03 '13 at 01:24

1 Answers1

2

Version 51 corresponds roughly to Java 7. Install openjdk-7-jre. or for development, openjdk-7-jdk.

This may be done with the command:

sudo apt-get install openjdk-7-jre

You may also opt for IcedTea, namely icedtea-7-jre-jamvm.

You can also compile the jar with compatibility level 1.6, though without special configuration you may encounter issues with certain libraries. You can't use a higher source than target on the compiler, so you'll need to forgo shortened generics such as:

ArrayList<Foo>=new ArrayList<>();

(fill in the type arguments instead) and other sorts of nifty 7-only features.

Community
  • 1
  • 1
nanofarad
  • 40,330
  • 4
  • 86
  • 117