Forum     

Go Back   Digit Technology Discussion Forum > Software > Open Source
Register FAQ Calendar Mark Forums Read

Open Source A place where you can talk to like-minded people about the fastest growing software movement today! Discuss anything and everything about Open Source software and Operating Systems.

Closed Thread
 
LinkBack (1) Thread Tools Display Modes
Old 12-08-2006, 10:10 AM   1 links from elsewhere to this Post. Click to view. #1 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Question Java Trouble

I decided to try out the Java tutorials at the Sun Microsystems Website, But I ran into some problems. See if you can help me out.

I've already installed the latest JDK, 6b2.

I followed the instructions here : http://java.sun.com/docs/books/tutor...java/unix.html , and copied the following code and saved it as HelloWorldApp.java

Code:
/**
 * The HelloWorldApp class implements an application that
 * simply prints "Hello World!" to standard output.
 */
class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}
It compiles fine, but when I try to run it, I get this mess :

Code:
sykora@nexus projects/> javac HelloWorldApp.java
sykora@nexus projects/> java HelloWorldApp 
Exception in thread "main" java.lang.ClassFormatError: HelloWorldApp (unrecognized class file version)
   at java.lang.VMClassLoader.defineClass (libgcj.so.7)
   at java.lang.ClassLoader.defineClass (libgcj.so.7)
   at java.security.SecureClassLoader.defineClass (libgcj.so.7)
   at java.net.URLClassLoader.findClass (libgcj.so.7)
   at java.lang.ClassLoader.loadClass (libgcj.so.7)
   at java.lang.ClassLoader.loadClass (libgcj.so.7)
   at java.lang.Class.forName (libgcj.so.7)
   at gnu.java.lang.MainThread.run (libgcj.so.7)
sykora@nexus projects/>
Can anyone tell me what I'm doing wrong? Is it the code which is bad (I doubt) or have I installed the wrong binaries? Or is it something else?
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 12-08-2006, 10:15 AM   #2 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,657
Default Re: Java Trouble

I dont know where the problem lies but please try to use the standard Sun Java 5 instead of GCJ libraries.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 12-08-2006, 10:16 AM   #3 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: Java Trouble

Can you tell me how I install those?
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 12-08-2006, 10:23 AM   #4 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,657
Default Re: Java Trouble

Which distro are you using

For FC5:
http://stanton-finley.net/fedora_cor...otes.html#Java

For Ubuntu:
http://ubuntuguide.org/wiki/Dapper#H...ozilla_Firefox
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 12-08-2006, 12:29 PM   #5 (permalink)
Broken In
 
harmax's Avatar
 
Join Date: Mar 2004
Location: chennai
Posts: 135
Default Re: Java Trouble

use netbeans www.netbeans.org itll solve al ur probs
__________________
WORK EXPANDS TO FILL THE TIME NEEDED FOR ITS COMPLETION
-------- PARKINSON\'S LAW
harmax is offline  
Old 12-08-2006, 01:34 PM   #6 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
Default Re: Java Trouble

Simple!

Ur problem is related to classpath! java wont execute even if u try like "java filename" in its directory in which file resides.

U can solve it by
1. Setting up the classpath
2. executing by giving full path . Like u have ur java file named "Hello.java" in /home/Sykora ...then it will compile preety easily if u give javac in that directory.
But to execute it u need to give command like "java /home/Sykora/Hello".

To setup the classpath i.e the path of directory containing all the java file and compiled java class files.........open up ur ".bash_profile" file hidden in ur home fodler and add entry at the end
***********************************
CLASSPATH=$HOME/Sykora
export CLASSPATH
***********************************


Neways u shud try 1st method..!!

UR problem Solved!!

Last edited by mediator; 12-08-2006 at 01:41 PM.
mediator is offline  
Old 12-08-2006, 07:28 PM   #7 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: Java Trouble

Code:
sykora@nexus ~/> java /home/sykora/HelloWorldApp
Exception in thread "main" java.lang.NoClassDefFoundError: /home/sykora/HelloWorldApp
   at gnu.java.lang.MainThread.run (libgcj.so.7)
Caused by: java.lang.ClassNotFoundException: /home/sykora/HelloWorldApp
   at java.lang.Class.forName (libgcj.so.7)
   at gnu.java.lang.MainThread.run (libgcj.so.7)
I tried both methods. It still gives me garbage. Like you said, the compiling works well enough. I can't run the bytecode. Is there possible anything else I have to install? So far I've installed only jdk.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 12-08-2006, 07:32 PM   #8 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,657
Default Re: Java Trouble

Did you install the Sun Java pack yet? GCJ gives me such errors too
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 12-08-2006, 07:34 PM   #9 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: Java Trouble

Which sun pack? If you mean downloading the jdk rpm from sun's website and installing it, yes I've done that. I tried doing what it said on the Stanton Finley notes but frankly, it doesn't work. I screwed up my $path and had to reboot.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 12-08-2006, 07:39 PM   #10 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,657
Default Re: Java Trouble

Thats weird, it went well with me.. ah well, I dont think I can be of much help anymore now, am sorry for that.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 12-08-2006, 08:01 PM   #11 (permalink)
Wise Old Owl
 
JGuru's Avatar
 
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
Default Re: Java Trouble

@Sykora, you have two options to choose:

Option - I:

Uninstall the GNU Java libraries (GCJ) & install Sun's JDK 5.0.

Option -II:
Since GCJ Java libraries are installed by default, if you install Sun's JDK 5.0, you
must configure your Java settings to use Sun's JDK, not GCJ libraries.

Now the Sun's JDK will be added to your PATH. And things will work fine.
I had the same problem in Ubuntu 6.06 (Dapper Drake), & I uninstalled the
package 'gij-4.1' & installed Sun's JDK 5.0. The problem was fixed!!

In you case, the GCJ Java libraries are executing the Java bytecode ; see the
error message: 'gnu.java.lang.MainThread.run(libgcj.so.7'.
Better option is uinstalling the GCJ Java libraries. Then your problem will be solved.
Which Linux distro you are using?
JGuru is offline  
Old 12-08-2006, 09:02 PM   #12 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
Default Re: Java Trouble

@Sykora........No man I also tried to compile first and then run it from different directory then the one with CLASSPATH. It failed like u said giving the same error.
You do one thing set the classpath from terminal itself first temprorarily like
"export CLASSPATH=/home/Sykora/java_file_classfiles_directory" and then do
"java HelloWorldApp"

I am sure this solves ur problem. I also have FC5!
mediator is offline  
Old 12-08-2006, 09:28 PM   #13 (permalink)
Wise Old Owl
 
JGuru's Avatar
 
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
Default Re: Java Trouble

@Mediator, your procedure is totally wrong!!

@Sykora, Here is the solution. I hope you have installed the Java JDK 5.0 'RPM' format.
Stanton Finley's procedure is for installing JRE, so that you can view Applets. For
Java developers , this is the procedure:

Download JDK 5.0(RPM format) & also J2SE 5.0 Documentation from here
Execute the file after logging in as root.
Configuration:
Open the Terminal Window & type:
$ su -
(Enter password)

# /usr/sbin/alternatives --config java

The Output:
There are 2 programs which provide 'java'.

Selection Command
--------------------------------------------------------------------------------
* 1 /usr/lib/jvm/jre-1.4.2-gcj/bin/java
+ 2 /usr/java/jdk1.5.0/bin/java

Now type 2, since you want the Sun's JDK 'java'.

# 2

Now type:
# /usr/sbin/alternatives --display java
You should see:
java - status is manual
link currently points to /usr/java/jdk1.5.0/bin/java
(The rest of the output follows here)

Also update the file : '/etc/profile.d/java.sh'
# gedit /etc/profile.d/java.sh

In the file, you should have the env variable 'JAVA_HOME'
JAVA_HOME=/usr/java/jdk1.5.0
export JAVA_HOME
PATH=$JAVA_HOME/bin: (The rest of path commands follow here)
export PATH

NOTE: Just check were Java is installed, this is given as a general procedure.
If you have installed 'JDK 5.0 Update 6' , it may be '/usr/java/jdk1.5.0_6'!!
So check it first.

Now save the file.
Logout & login to see the changes.
Now your JAVA problem should be fixed.
If you want to work in good Java IDE , as a beginner in Java language, NetBeans
is not for you. It's for Professional Java developers. Sun has developed a smaller
version of NetBeans called NetBeans IDE 5.0 BlueJ Edition. It's ideal for
programmers new to Java language & it's easy to use. Get it from here

Last edited by JGuru; 13-08-2006 at 12:08 AM. Reason: Automerged Doublepost
JGuru is offline  
Old 13-08-2006, 12:26 AM   #14 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
Default Re: Java Trouble

@JGURU....why am I wrong? I have already reinstalled java on FC5. With this u get java and javac in ur PATH. Isnt that correct? And if u dont u can specify java PATH !! Simple!
And as for CLASSPATH ....I'm dead sure !! It will work 100%....I can bet on it!
If @Sykora has compiled it with javac then java will also work 100%.

I dunno why u say totally wrong! Please Explain!

Last edited by mediator; 13-08-2006 at 12:28 AM.
mediator is offline  
Old 13-08-2006, 08:55 AM   #15 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: Java Trouble

@JGuru :
I think I have isolated my problem, or so I think.
Code:
[root@nexus]/home/sykora/downloads# rpm -ivh jdk-1_5_0_07-linux-i586.rpm
Preparing...                ########################################### [100%]
   1:jdk                    ########################################### [100%]
[root@nexus]/home/sykora/downloads# /usr/sbin/alternatives --config java

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java

Enter to keep the current selection[+], or type selection number:
It isn't even turning up in the menu. What have I done wrong?
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 13-08-2006, 12:02 PM   #16 (permalink)
Wise Old Owl
 
JGuru's Avatar
 
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
Default Re: Java Trouble

@Sykora, that means that Sun's JDK was not installed!!
You need to download Sun's 'J2SE(TM) Development Kit Update 8' & click on 'Linux
RPM in self-extracting file' The file size is 45.48 MB.
Open the Terminal Window & login as root:
$ su -
(Enter password)
# ./jdk-1_5_0_08-linux-i586-rpm.bin
Now you'll get the License Agreement , Press the 'Spacebar' to move to the
next page. You must type 'yes'. Also because of Fedora's 'SE Linux' policy, which
it enforces by default. Maybe Sun's JDK was not installed!!
.So change your 'SE Linux'
policy in Fedora & try again. Java 'jdk1.5.0_08' should appear in the menu.

@Mediator, this is correct recommended way to do it.

Last edited by JGuru; 13-08-2006 at 12:04 PM.
JGuru is offline  
Old 13-08-2006, 12:42 PM   #17 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: Java Trouble

I disabled my SELinux and redownloaded the rpm-bin file. I ran it and accepted the agreement, and installed. I'm still getting only one option on the config list. Should I try removing gcj? I'm running all of this as root, if it makes any difference.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Old 13-08-2006, 01:00 PM   #18 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
Default Re: Java Trouble

@Jguru.....The steps u told .........i already know them! But bro....this is the correct way of just installing.
@Sykora is having problems in running the compiled file. He already has compiled the file....that means Java is running perfectly OK! and CLASSPATH is not setup coz the compiled file not being run!..............@Sykora did u setup the CLASSPATH?
mediator is offline  
Old 13-08-2006, 03:50 PM   #19 (permalink)
Wise Old Owl
 
JGuru's Avatar
 
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
Default Re: Java Trouble

@Sykora, JDK 1.5.0 RPM usually installs Java JDK in the path '/usr/java/jdk1.5.0'.
Browse your File System & go to location '/usr'.See if there is a 'java' directory under
the '/usr' directory. You can also search for 'java' using 'File Search' , in the search
directory , select 'File System'. If you do find 'jdk1.5.0_08' directory & all sub-directories
like demo etc., under it. Uinstall (remove) gcj Java libraries.
Open the file '/etc/profile.d/java.sh'
And add the line :
JAVA_HOME=/usr/java/jdk1.5.0_08
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
save the file now.
Logout & login for the changes to take effect.
JGuru is offline  
Old 13-08-2006, 04:18 PM   #20 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
Wink Re: Java Trouble

Quote:
Originally Posted by JGuru
@Sykora, JDK 1.5.0 RPM usually installs Java JDK in the path '/usr/java/jdk1.5.0'.
Browse your File System & go to location '/usr'.See if there is a 'java' directory under
the '/usr' directory. You can also search for 'java' using 'File Search' , in the search
directory , select 'File System'. If you do find 'jdk1.5.0_08' directory & all sub-directories
like demo etc., under it. Uinstall (remove) gcj Java libraries.
Open the file '/etc/profile.d/java.sh'
And add the line :
JAVA_HOME=/usr/java/jdk1.5.0_08
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
save the file now.
Logout & login for the changes to take effect.
Heyy thats cheating! @JGURU u aint tell me why i was wrong! The stuff u posted above is for setting path which @Sykora didnt need to coz he already has "javac and java in its path".........@SYKORA....isnt it? Neways put it in ur path if u dont have!

Neways What happened to CLASSPATH? Thats guaranteed to work! Satisfaction will be guaranteed!
mediator is offline  
Old 13-08-2006, 04:32 PM   #21 (permalink)
Wise Old Owl
 
JGuru's Avatar
 
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
Default Re: Java Trouble

@Mediator, The Java libraries that are installed by default are GNU Java libraries.
Sun's JDK is the reference implementation. The Java @Sykora has is gcj libraries,
not Sun's JDK!! This is not cheating. I have more than 5 years working experience
in Java. How many years experience you have @Mediator? How many Java
applications you have developed?? I'm Sun Cerified Java Programmer. I also hold
BrainBench certification in Java. Let's put an end to this unnecessay futile argument!!
JGuru is offline  
Old 13-08-2006, 04:51 PM   #22 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
Default Re: Java Trouble

Heyyy! @JGURU Calm down. No args. But u shud have told y I was wrong.
Ok u have more experience! I have worked for around 2 yrs on java now and have made many applications in java mainly in networking area!

But what @Sykora experience .......Exactly I also experienced that! And I have solved it by just configuring CLASSPATH! Dont get so proud because u have more experience. Most of the times even teachers think that a student is useless and doesnt know anything.....whereas the fact can be very contrasting and opposite!

EPEACE!
mediator is offline  
Old 13-08-2006, 05:06 PM   #23 (permalink)
18 Till I Die............
 
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
Default Re: Java Trouble

This thread is so confusing. I am facing the same problem too for many java programs. I am on ubuntu 6.06 and it seems I have Sun Java recognised here.
__________________
http://www.bash.org/?258908
mehulved is offline  
Old 13-08-2006, 05:44 PM   #24 (permalink)
String Phreak
 
mediator's Avatar
 
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
Default Re: Java Trouble

Quote:
Originally Posted by Sykora
sykora@nexus ~/> java /home/sykora/HelloWorldApp
Exception in thread "main" java.lang.NoClassDefFoundError: /home/sykora/HelloWorldApp
at gnu.java.lang.MainThread.run (libgcj.so.7)
Caused by: java.lang.ClassNotFoundException: /home/sykora/HelloWorldApp
at java.lang.Class.forName (libgcj.so.7)
at gnu.java.lang.MainThread.run (libgcj.so.7)
U tried only the 2nd way? Please try the first method too! and @tech_for_future u too! Atleast tell the outcome of CLASSPATH method! U wont have to write "java /home/sykora/HelloWorldApp" then ..............only "java HelloWorldApp"......and that too anywhere, in any directory !
mediator is offline  
Old 13-08-2006, 09:40 PM   #25 (permalink)
Broken In
 
harmax's Avatar
 
Join Date: Mar 2004
Location: chennai
Posts: 135
Default Re: Java Trouble

guys dont bang ur head, jus use netbeans or eclipse , and put ur efforts in creating applications rather than tryin to get it to even compile

yeah i do accept that my solution is jus a dirty work around
__________________
WORK EXPANDS TO FILL THE TIME NEEDED FOR ITS COMPLETION
-------- PARKINSON\'S LAW
harmax is offline  
Old 13-08-2006, 09:46 PM   #26 (permalink)
I see right through you.
 
Sykora's Avatar
 
Join Date: Sep 2005
Location: Chennai
Posts: 597
Default Re: Java Trouble

Thanks JGuru, your solution worked flawlessly. I think I was getting mixed up in the path where my java was installed. I don't know why.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
Sykora is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


LinkBacks (?)
LinkBack to this Thread: http://www.thinkdigit.com/forum/open-source/33880-java-trouble.html
Posted By For Type Date
No puedo ejecutar los programas en java | Ubuntu-es This thread Refback 03-03-2011 06:03 AM


All times are GMT +5.5. The time now is 11:39 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2