Results 1 to 7 of 7
  1. #1
    strpwr is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default Error while running jar outside of IDE

    I have a program that compiles and runs well in NetBeans. When I create a jar file and try to run on my linux via CLI, I get the following:
    [root@lizard dist]# java -jar AxisCamera.jar
    Exception in thread "main" java.lang.ClassFormatError: axiscamera.axiscamera (unrecognized class file version)
    at java.lang.VMClassLoader.defineClass(libgcj.so.7rh)
    at java.lang.ClassLoader.defineClass(libgcj.so.7rh)
    at java.security.SecureClassLoader.defineClass(libgcj .so.7rh)
    at java.net.URLClassLoader.findClass(libgcj.so.7rh)
    at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj .so.7rh)
    at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
    at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
    at gnu.java.lang.MainThread.run(libgcj.so.7rh)
    Does this have to do with my import statements or CLASSPATH or something else?
    Thanks in advance?

  2. #2
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,641
    Rep Power
    7

    Default

    Exceptions such as this occur when trying to compile and run with differing version of the JDK and JVM. For even more detail, check the versions you are using of each (eg 'java -version' and 'javac -version'). Try updating the JVM on the machine you are attempting to run the jar on, or compile and specify the minor version (may not be possible if your code requires later versions of the java API)

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,901
    Rep Power
    25

    Default

    It could do with different versions of java. Compile with younger, execute with older.
    Or it could be a corrupted class file. Can you extract the class file mentioned and look at the first few bytes in a hex editor. They should look like this:
    CAFEBABE0003002D001401000443

  4. #4
    strpwr is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    # java -version
    java version "1.4.2"
    gij (GNU libgcj) version 4.1.2 20080704 (Red Hat 4.1.2-50)
    # javac -version
    Eclipse Java Compiler v_677_R32x, 3.2.1 release, Copyright IBM Corp 2000, 2006. All rights reserved.

    I think you are correct. I did the same two commands on my MAC where the app works and it shows 1.6.0_24 for both java and javac. Would this be a $PATH issue?

  5. #5
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,901
    Rep Power
    25

    Default

    It appears that you are not using Oracle's java or javac commands. Have you tried installing the JDK vs using gij?

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,458
    Rep Power
    20

    Default

    Get rid of the silly GNU Java aka 'Fake Java' and install a Sun/Oracle JRE (or JDK if you want to develop on the Linux box).

    db

  7. #7
    strpwr is offline Member
    Join Date
    Jun 2011
    Posts
    3
    Rep Power
    0

    Default

    Ok, on RHEL where this wasn't working I had to re-link the symbolic link in /etc/alternatives/java to my jdk. This is what I did:
    # rm /etc/alternatives/java
    rm: remove symbolic link `/etc/alternatives/java'? y

    # ln -s /usr/java/jdk1.6.0_25/bin/java /etc/alternatives/java

    All is well now. Thanks everyone for pointing out the version mismatch.

Similar Threads

  1. Java running error
    By distant_smile in forum New To Java
    Replies: 10
    Last Post: 01-23-2011, 07:19 AM
  2. Runtime Error running in UVA
    By mathfxr in forum Advanced Java
    Replies: 10
    Last Post: 09-18-2010, 02:50 AM
  3. Odd error when running app
    By pahiker in forum New To Java
    Replies: 5
    Last Post: 06-23-2010, 04:10 PM
  4. Error during running
    By ak88 in forum New To Java
    Replies: 7
    Last Post: 07-28-2009, 05:39 AM
  5. error while running jar file
    By ernieBob in forum NetBeans
    Replies: 1
    Last Post: 03-25-2008, 12:13 PM

Posting Permissions

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