This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Cant use java to execute files Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Cant use java to execute files" Watch "Cant use java to execute files" New topic
Author

Cant use java to execute files

Suvojit Chakraborty
Ranch Hand

Joined: Nov 10, 2009
Posts: 59
Hello guys,

I am facing a weird problem. Whenever I am trying to execute a java program I get NoclassdefFound error and on including class path on command line I get bulk of error messages.

foll is a normal code which compiles error free(It is really a simple one)



I get this output:


Please tell me whats wrong in this?

thanks
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
Most likely, you have compiled the .java files with a more recent version of "javac" than the version of "java" you are using to execute it. Please use copy and paste not screenshots.

Execute the following commands:
java -version
javac -version

Examine your system and user PATH for older versions of Java preceding newer versions. If you are using -cp . then you have probably made some sort of mistake setting a classpath. It is usually a mistake to set a system classpath at all, so if you set a system classpath yourself, remove it. If the classpath was set automatically, add .; to its beginning.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please post text for textual information rather than screenshots.

Edit: whoops, missed the previous exhortation; sorry.
Suvojit Chakraborty
Ranch Hand

Joined: Nov 10, 2009
Posts: 59
Campbell Ritchie wrote:Most likely, you have compiled the .java files with a more recent version of "javac" than the version of "java" you are using to execute it.


Oh yes....I found the version of java as 1.3 in my system and javac as 1.6. Strangely, I dont know how Java interpreter became 1.3. Till yesterday everything was Ok and I was compiling and running my programs without any error.

But now I have installed JRE1.6 but still the problem persist.
please help to fix it.
Please use copy and paste not screenshots.



Ok I will take care of this in future.

Thanks
John de Michele
Rancher

Joined: Mar 09, 2009
Posts: 600
Suvojit:

Did you change your path to make sure that the 1.6 version of java and javac are being called?

John.
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 159

The 'public' that should be in front of the word 'class' is missing.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

Carey Brown wrote:The 'public' that should be in front of the word 'class' is missing.

Classes don't need to be public to be executed.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Ooo, I had no idea.
Suvojit Chakraborty
Ranch Hand

Joined: Nov 10, 2009
Posts: 59
John de Michele wrote:

Did you change your path to make sure that the 1.6 version of java and javac are being called?



Oh yes! Environment variables are pointing to right folders.
here is the status of the path n classpath

classpath:C:\Program Files\Java\jre6;C:\Program Files\Java\jdk1.6.0_20\bin

path:H:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Java\jdk1.6.0_20\bin;C:\Program Files\Java\jre6

and following is result of jave -version:


I dont know what happened. Everything was OK till Thursday.....
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 8439

Suvojit Chakraborty wrote:
path:H:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Java\jdk1.6.0_20\bin;C:\Program Files\Java\jre6


What is C:\Program Files\Oracle\jre\1.3.1\bin;? Jre as in Java JRE?
The System will pick up the first JDK/JRE it finds. Ideally you should have only one JAVA_HOME variable on your system which points to your Java installation directory.


[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
Suvojit Chakraborty
Ranch Hand

Joined: Nov 10, 2009
Posts: 59
Maneesh Godbole wrote:

What is C:\Program Files\Oracle\jre\1.3.1\bin;? Jre as in Java JRE?


I dont know what is this. I installed Oracle recently. Maybe it got installed along with oracle.
I will try to swap it with JDK's path. Let me see if this works......[fingers crossed]
Suvojit Chakraborty
Ranch Hand

Joined: Nov 10, 2009
Posts: 59
Maneesh Godbole wrote:
Suvojit Chakraborty wrote:
path:H:\oracle\ora92\bin;C:\Program Files\Oracle\jre\1.3.1\bin;C:\Program Files\Oracle\jre\1.1.8\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\Program Files\Microsoft SQL Server\100\Tools\Binn\;C:\Program Files\Microsoft SQL Server\100\DTS\Binn\;C:\Program Files\Java\jdk1.6.0_20\bin;C:\Program Files\Java\jre6


What is C:\Program Files\Oracle\jre\1.3.1\bin;? Jre as in Java JRE?
The System will pick up the first JDK/JRE it finds. Ideally you should have only one JAVA_HOME variable on your system which points to your Java installation directory.




phew!!! at last its working.....I have put jdks path before oracles path.
Thank you mate.....u saved me from this mess, I was so frustrated...Thanks you so much....
now java n javac -version generates foll:
C:\Documents and Settings\suvojit123>javac -version
javac 1.6.0_20

C:\Documents and Settings\suvojit123>java -version
java version "1.6.0_20"
Java(TM) SE Runtime Environment (build 1.6.0_20-b02)
Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing)


But I am still confused how and why did the classpath get swapped n whats is jre's connection with oracle....I am asking just out of curiosity. It will be great if you can anwser...

Thanks Again
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 8439

You mean the path, not classpath.

Like I mentioned before, the system will pick up the first JDK/JRE it finds.
I am guessing, someone installed some Oracle related stuff on your system. Maybe it came bundled with the 1.3 version?
Suvojit Chakraborty
Ranch Hand

Joined: Nov 10, 2009
Posts: 59
Maneesh Godbole wrote:You mean the path, not classpath.


Yes


Like I mentioned before, the system will pick up the first JDK/JRE it finds.
I am guessing, someone installed some Oracle related stuff on your system. Maybe it came bundled with the 1.3 version?


Yes I installed oracle 9i recently.
I understood that java must have came bundled with it but what has java to do in oracle? This is my question.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
A lot of Oracle is written in Java and it is notorious for adding an old version of Java at the beginning of your PATH. Something to do with its installer.

You should delete that classpath environment variable altogether, and not put your work into those folders.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Cant use java to execute files
 
Similar Threads
jsp.JspException: No collection found
Difference detween execute() and executeUpdate()..?
NoClassDefFoundError
Execution problems
java invocation error