Hi everyone,
Please list exactly what you are typing at the command line
Richard West
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
That's different JVM implementations. You're getting the major/minor version error, because you might have compiled a project in 1.5 and trying to run it on 1.4.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
Hi everyone,
That's different JVM implementations. You're getting the major/minor version error, because you might have compiled a project in 1.5 and trying to run it on 1.4.
server_crash, you mean you can't compile a java file in 1.5 and run it in 1.4 although the vice-versa works?
Richard West
*****************************************************
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
Exactly. 1.5 is suppose to be backward compatible when you compile with the 1.4 source flag, but the JVM implementation is still different, which in turn causes the major/minor version error. I had this same problem a while back. I compiled the source in perfect 1.4 syntax, but it gave me the same error. I then tried to compile with the 1.4 -source flag, but that didn't help any. After that, I learned that the implemenation details were still different no matter what. Of course, if you use 1.5 syntax it definately won't work on 1.4 JVMs and JREs. It's weird since they call it backward compatible, but it's really not.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
Hi everyone,
when i'm typing "javac hello.java" in comandline after entering in that directory it is saying
bash: javac comand not found
Yours is a classic classpath error.
Do this
javac cp hello.java
It'll work now. Remember to type the location of your file and not only hello.java. The same goes for the javac compiler
Richard West
*****************************************************
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
If you add the -source 1.4 flag you will NOT get 1.4 compatible classfiles. All that does is flag 5.0 only features as errors in the code, effectively ensuring whether it would compile using a 1.4 compiler.
You also need to add the -target 1.4 flag.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Hello,
Background
The reason you are receiving the 'UnsupportedClassVersionError' is because the 'bash' shell is finding the default installed 'java' bundled with MDK (Mandrake) 10. You can find which 'java' or 'javac' (or any command) will be run by bash by entering the following command:
which <command>
For instance, below is the output I get on my machine when I want to see which java binary will be run:
kate@pioneer:[~]$ which java
/home/kate/jdk.1.5.0.03/bin/java
I suspect yours may be running '/usr/bin/java'. This is the 'Kaffe Virtual Machine' environment and not much good for anything except taking up disk space. It lacks compatibility in many ways with the current releases of Java.bash: javac comand not found
This is an error being raised by the bash shell, as it cannot locate an executable called 'javac' in the locations specified in your 'PATH' environment variable.but when i'm copying the hello.java into /java/bin/ and cd to /java/bin/ and typing "./javac hello.java" it is creating hello.class and its working
The bash shell cannot locate the 'javac' binary because you have installed the JDK directly into the root directory. The reason that executing './javac hello.java' works (after you have copied hello.java into that directory and changed directory to that path) is because by placing './' in front of 'javac' overrides your PATH environment variable and instructs bash to search for the binary called 'javac' in the current working directly only, which of course it finds.Solution
tell me how to run it if the .java file is in some other directory
You need to add '/java/bin/' to your sessions PATH environment variable. To do this enter the command as below:
export PATH=/java/bin/:$PATH
However when you close your shell session or begin a new one you will have to re-export this path. To make this change permanent (so it is set automatically each time you start a new shell session) you need to place this into your '.bashrc' (bash resource) file. This file is located in your home directory. For example my '.bashrc' file is located in the following location '/home/kate/.bashrc'. Simply add the command above to the end of this file.For future reference
It is bad practice to install software into the root directory on Linux. You should install the JDK (or any software for use by you only) into your home directory. If you want to install something which can be accessed by any other user of the machine you should install it under the '/usr/local/' directory as the root user.
If you want to rectify this you can move the installed JDK into your home directory by issuing the following command:
mv /java /home/<your_user_name>/
Now just change the line you added to the '.bashrc' file to point to '/home//java/bin' instead.
Hope this helps,
Kate
Kate Albany
Junior Poster in Training
71 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1
Hi everyone,
You guys mean that the -cp flag does not work in mandrake but only on windows?
Richard West
freesoft_2000
Practically a Master Poster
623 posts since Jun 2004
Reputation Points: 25
Solved Threads: 10
Hi,
No, the -cp flag works just the same under Linux. This problem is not classpath related though.
Kate
Kate Albany
Junior Poster in Training
71 posts since Jun 2005
Reputation Points: 10
Solved Threads: 1
If you add the -source 1.4 flag you will NOT get 1.4 compatible classfiles. All that does is flag 5.0 only features as errors in the code, effectively ensuring whether it would compile using a 1.4 compiler.
You also need to add the -target 1.4 flag.
But remember that the 1.4 target flag still doesn't change the implementation details. If you remember right, I had a similar problem where I wanted 1.4 source code written in 1.5 to work on 1.4 JRE's, but it never did. You told me to try those flags, and from there we decided that the details were still different.
server_crash
Postaholic
2,111 posts since Jun 2004
Reputation Points: 113
Solved Threads: 20
You need them both. Either on its own will not work to produce a 1.4 classfile (the target flag alone MIGHT work if you're very careful, the source flag alone certainly won't).
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337