Results 1 to 6 of 6

Thread: Trying to get Java to execute...

  1. #1
    Join Date
    Feb 2012
    Beans
    5

    Trying to get Java to execute...

    I am a total noob to Linux. I am in a "Intro to Java" class this semester and I am trying to get Java running correctly in Ubuntu 11.10. I got Windows 7 64-bit to compile and execute Java in cmd, but it's totally bugging me that I cannot get it to run in Ubuntu...

    javac -version
    javac 1.7.0_147


    java -version
    java version "1.6.0_23"
    OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.2)
    OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)

    In my directory:
    /usr/lib/jvm

    It has the following folders.
    java-1.6.0-openjdk
    java-6-openjdk
    java-1.7.0-openjdk-amd64
    java-7-openjdk-amd64
    java-7-openjdk-common
    jdk1.7.0

    I am having trouble executing java file. I get this message...

    javac Hello.java

    java Hello
    Exception in thread "main" java.lang.UnsupportedClassVersionError: Hello : 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(Secure ClassLoader.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.j ava:205)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 21)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 66)
    Could not find the main class: Hello. Program will exit.

    Could it be my PATH is set to an older version of Java?
    Last edited by D3vin; March 14th, 2012 at 04:16 AM.

  2. #2
    Join Date
    Nov 2006
    Beans
    1,199

    Re: Trying to get Java to execute...

    This is the site i use to install Java might be helpful
    http://sites.google.com/site/easylinuxtipsproject/java

  3. #3
    Join Date
    Feb 2012
    Beans
    5

    Re: Trying to get Java to execute...

    Quote Originally Posted by Gremlinzzz View Post
    This is the site i use to install Java might be helpful
    http://sites.google.com/site/easylinuxtipsproject/java

    Thank you! But it didn't work. I uninstalled the Icetea plugin and installed the Oracle Java 1.6.0 JRE, also set it as primary.

    Now it goes something like this.

    java -version
    java version "1.6.0_31"
    Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
    Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)

    java Hello
    Exception in thread "main" java.lang.UnsupportedClassVersionError: Hello : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(Unknown Source)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknow n Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$000(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    Could not find the main class: Hello. Program will exit.

    I saved the java file and class file in my Home folder.

  4. #4
    Join Date
    Jul 2006
    Location
    Castrum, Germania Secunda
    Beans
    1,071

    Re: Trying to get Java to execute...

    Forget the Hello. You can check here whether Java works:
    http://www.java.com/en/download/installed.jsp

    If that confirms that all is well, all is well. For all practical purposes, that's quite enough. At least for 99,9 % of the Ubuntu users.

    When no such confirmation: repeat the installation manual, and follow it to the letter this time. Success guaranteed.

  5. #5
    Join Date
    Apr 2006
    Beans
    800
    Distro
    Lubuntu 12.04 Precise Pangolin

    Re: Trying to get Java to execute...

    The error message "unsupported major.minor version" means that you compiled your class with a specific JDK, but then try to run it in an older version of JDK. In your case you are compiling with jdk1.7 and try to run it with java 1.6. I would suggest you to uninstall jdk1.7.0 and install jdk1.6, recompile and then you should be able to run it.

    @Pjotr OP wanted help with compiling with Java JDK, not installing Java JRE/Plugin.
    Last edited by lykeion; March 15th, 2012 at 09:47 PM.

  6. #6
    Join Date
    Jan 2007
    Location
    the outer rim
    Beans
    367
    Distro
    Kubuntu 12.04 Precise Pangolin

    Re: Trying to get Java to execute...

    The easiest way to do this is to create a folder in /home, call it what you like and install the jdk there. What you've done from the looks of it is install the jdk alongside the openjdk wich is not necessary.
    All you need to do is set the bash path variable.
    With this done you can compile from the command line no problem.
    The bash path is set in a hidden file in your /home called .bashrc.
    Last edited by Immolatus; March 16th, 2012 at 04:25 AM. Reason: typo
    illegitimi non carborundum

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •