| Forum |
|
|||||||
| 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. |
![]() |
|
|
LinkBack (1) | Thread Tools | Display Modes |
|
|
#1 (permalink)
|
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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.
}
}
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/>
__________________
I didn't make the world, I only try to live in it. http://lucentbeing.com -- Sykora -- |
|
|
| Advertisements. Register and be a member of the community to get rid of them. | |
|
Advertisement
|
|
|
|
#4 (permalink) |
|
Commander in Chief
Join Date: Jul 2005
Posts: 6,657
|
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 |
|
|
|
|
#5 (permalink) |
|
Broken In
Join Date: Mar 2004
Location: chennai
Posts: 135
|
use netbeans www.netbeans.org itll solve al ur probs
__________________
WORK EXPANDS TO FILL THE TIME NEEDED FOR ITS COMPLETION -------- PARKINSON\'S LAW |
|
|
|
|
#6 (permalink) |
|
String Phreak
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
|
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. |
|
|
|
|
#7 (permalink) |
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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 didn't make the world, I only try to live in it. http://lucentbeing.com -- Sykora -- |
|
|
|
|
#9 (permalink) |
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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 -- |
|
|
|
|
#11 (permalink) |
|
Wise Old Owl
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
|
@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? |
|
|
|
|
#12 (permalink) |
|
String Phreak
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
|
@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! |
|
|
|
|
#13 (permalink) |
|
Wise Old Owl
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
|
@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 |
|
|
|
|
#14 (permalink) |
|
String Phreak
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
|
@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. |
|
|
|
|
#15 (permalink) |
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
@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:
__________________
I didn't make the world, I only try to live in it. http://lucentbeing.com -- Sykora -- |
|
|
|
|
#16 (permalink) |
|
Wise Old Owl
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
|
@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. |
|
|
|
|
#17 (permalink) |
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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 -- |
|
|
|
|
#18 (permalink) |
|
String Phreak
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
|
@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? |
|
|
|
|
#19 (permalink) |
|
Wise Old Owl
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
|
@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. |
|
|
|
|
#20 (permalink) | |
|
String Phreak
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
|
Quote:
Neways What happened to CLASSPATH? Thats guaranteed to work! Satisfaction will be guaranteed! |
|
|
|
|
|
#21 (permalink) |
|
Wise Old Owl
Join Date: Dec 2005
Location: Space-time continuum
Posts: 1,646
|
@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!! |
|
|
|
|
#22 (permalink) |
|
String Phreak
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
|
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! |
|
|
|
|
#23 (permalink) |
|
18 Till I Die............
Join Date: Jul 2004
Location: India, Mumbai, Marine Lines
Posts: 5,792
|
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 |
|
|
|
|
#24 (permalink) | |
|
String Phreak
Join Date: Mar 2005
Location: In ur Evil Mind!
Posts: 2,453
|
Quote:
|
|
|
|
|
|
#25 (permalink) |
|
Broken In
Join Date: Mar 2004
Location: chennai
Posts: 135
|
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 |
|
|
|
|
#26 (permalink) |
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
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 -- |
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
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 | |