LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   unrecognized class file version : when running simple Java program (http://www.linuxquestions.org/questions/linux-newbie-8/unrecognized-class-file-version-when-running-simple-java-program-686753/)

yuubouna 11-27-2008 09:05 PM

unrecognized class file version : when running simple Java program
 
1) I cannot run Simple Java program in Linux.
After executing
javac HelloWorldApp.java
HelloWorldApp.class is created, but when I try to run

java HelloWorldApp
the following error occured:
------------
javac HelloWorldApp.java
Exception in thread "main" java.lang.ClassFormatError: poi.HelloWorldApp (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 java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at gnu.java.lang.MainThread.run(libgcj.so.7rh)
------------


I thought the java version is the case, so I create symbolic link to changed the java version,to points from /usr/local/java to /jdk1.6.0_10 (Am I correct with this one?):
------------
ln -s /usr/local/java /usr/local/jdk1.6.0_10
------------


2) Then running:
java -version

RESULTS TO:
------------
java version "1.4.2"
gij (GNU libgcj) version 4.1.2 20071124 (Red Hat 4.1.2-42)

Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
------------

and
javac -version

RESULTS TO:
------------
javac 1.6.0_10
------------

but It doesn`t solved my problem, anyhow.

3) How to permanently set the path, Java_home, classpath in order to points out to the my new jdk version?

-Does the javac and java version must agree with their version?
-Is the "unrecognized class file version" error is because of java version?

Any help is appreciated.

Cheers,
jackie

yuubouna 11-27-2008 11:25 PM

I solved it!

The reason why I cannot run is, my java and javac version do not agree with each other.
To set up a Java_home permanently, I add the following to [.bash_profile]
If you cannot see the .bash_profile
ls -al - will show all the hidden files.

----------------
.bash_profile
----------------
export JAVA_HOME=/usr/local/jdk1.6.0_10
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib


Now my java, javac version agree with each other.
they are both: jdk1.6.0_10


----------------
Another thing is, When running Java program with Package directory,
Is the same concept when Running Java program in DOS env.
----------------
$ javac poi/impl/HelloWorld.java
$ java poi.impl.HelloWorld
Hello World!

this thread, helps me out, ;-)

Cheers!
jackie


All times are GMT -5. The time now is 10:44 PM.