Error while compilling program on Linux

R

ruds

Hi,
I want to execute a program on linux but it is giving me an error:
"Syntax error, 'for each' statements are only available if source
level is 5.0"
I have JDK 1.6 installed and my JAVA_HOME and CLASSPATH variable are
having the paths correct, still I'm getting this error.
On checking the version: javac -version I'm getting: Eclipse Java
Compiler v_677_R32x, 3.2.1 release
this is happening even if I expicitly set the $CLASSPATH.
I have set CLASSPATH in my .profile too.
This program was working perfectly 10 days ago and now suddenly it has
started giving errors.
What might be the problem?
Please help.
 
A

Andreas Leitgeb

ruds said:
I want to execute a program on linux but it is giving me an error:
"Syntax error, 'for each' statements are only available if source
level is 5.0"

Something seems to be telling your compiler to expect some older
source.
I have JDK 1.6 installed and my JAVA_HOME and CLASSPATH variable are
having the paths correct, still I'm getting this error.
On checking the version: javac -version I'm getting: Eclipse Java
Compiler v_677_R32x, 3.2.1 release

If you have the "JDK 1.6" installed, I'd expect "javac" to be the
jdk's javac, not eclipse's.

At command line (assuming bash - start one, otherwise), enter
type -all javac
and see, which paths all contain a javac, and which of them
is first one.

If you see some common path, like /usr/bin/javac, then also do
an "ls -l /usr/bin/javac" to see, if it happens to be some symlink
to somewhere else.

Of course, there's also the question, of what *seemingly irrelevant*
(you surely have thought about the others, already) changes you
have done to the system *before* you first noticed the error.

Even with eclipse's javac, you could try explicit -source 5
option to see if that would override any other defaults.

But more likely, some change caused a reordering of the javac's
found on your system.
this is happening even if I expicitly set the $CLASSPATH.
I have set CLASSPATH in my .profile too.

You shouldn't do that. I'm counting on Lew & others to explain
better, in how far this is really a bad idea...
 
N

Nigel Wade

Hi,
I want to execute a program on linux but it is giving me an error:
"Syntax error, 'for each' statements are only available if source
level is 5.0"
I have JDK 1.6 installed and my JAVA_HOME and CLASSPATH variable are
having the paths correct, still I'm getting this error.

Neither of those environment variables affect which executable gets run
when you type the javac command.
On checking the version: javac -version I'm getting: Eclipse Java
Compiler v_677_R32x, 3.2.1 release
this is happening even if I expicitly set the $CLASSPATH.
I have set CLASSPATH in my .profile too.
This program was working perfectly 10 days ago and now suddenly it has
started giving errors.
What might be the problem?
Please help.

Installing Eclipse may have put the Eclipse javac binary before the JDK
in the PATH. If so, it's simply a matter of fixing your PATH so that JDK
path comes first.

You don't say what flavour of Linux you have, but another possible
explanation is that it uses "alternatives", and installing Eclipse has
overridden the default Java compiler setting.

To see if this is the case type (you may need to be root to do this):

update-alternatives --list javac

If alternatives is installed, and it is being used to provide alternate
Java installations, this should tell you which javac are available.
You can use the update-alternatives command to switch between the
installed Java implementations.
 
M

Martin Gregorie

Hi,
I want to execute a program on linux but it is giving me an error:
"Syntax error, 'for each' statements are only available if source level
is 5.0"
I have JDK 1.6 installed and my JAVA_HOME and CLASSPATH variable are
having the paths correct, still I'm getting this error. On checking the
version: javac -version I'm getting: Eclipse Java Compiler v_677_R32x,
3.2.1 release
So, have you updated your distro during the 10 days since it was working
correctly?

If so, what packages were upgraded or installed, either as part of a
distro update or explicitly??

this is happening even if I expicitly set the $CLASSPATH.
As others have said, this is irrelevant. More to the point, what's in
$PATH and $JAVA_HOME?
 
R

ruds

Thanks you all,
did check the alternatives and selected the jdk1.6, and the program
worked.
 
R

Roedy Green

This program was working perfectly 10 days ago and now suddenly it has
started giving errors.
What might be the problem?

see http://mindprod.com/jgloss/javacexe.html
to find out what he default settings are and what setting you are
using.

In Ant it looks like this:

<javac source="1.5" target="1.5" srcdir="com/mindprod/amper"
sourcepath="${basedir}" classpath="${basedir}" debug="on"
includeAntRuntime="false">
<compilerarg value="-Xlint:unchecked" />
<compilerarg value="-Xlint:fallthrough" />
<compilerarg value="-Xlint:deprecation" />
</javac>

see http://mindprod.com/jgloss/ant.html

If you are compiling other than a single directory of files at a time,
you should be using ANT or equivalent.
--
Roedy Green Canadian Mind Products
http://mindprod.com
How long did it take after the car was invented before owners understood
cars would not work unless you regularly changed the oil and the tires?
We have gone 33 years and still it is rare to uncover a user who
understands computers don't work without regular backups.
 
A

Andreas Leitgeb

Nigel Wade said:
Why? What has that page got to do with locating the executable javac
(NOT javac.exe) on Linux? It's entirely Windows-centric (like most of
your website).
Other than self-promoting your website, what was the purpose of your reply?

At some point in the past, Roedy explained that his vision is not the
best, and so he doesn't always completely read the problems, but spots
some buzzwords and just for the chance that it may be a hit, posts a
link for that buzzword. Quite often it is a good hit, because quite
often it's the same questions asked again and again by newbies.

I'd wager the benefit of a link that happens to hit the nail on the head
much higher, than the "cost" of a miss.
 
L

Lew

Andreas said:
Nigel Wade wrote:
At some point in the past, Roedy explained that his vision is not the
best, and so he doesn't always completely read the problems, but spots
some buzzwords and just for the chance that it may be a hit, posts a
link for that buzzword. Quite often it is a good hit, because quite
often it's the same questions asked again and again by newbies.

I'd wager the benefit of a link that happens to hit the nail on the head
much higher, than the "cost" of a miss.

+1.

Besides, mindprod.com is a great site.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top