LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 05-05-2010, 11:44 PM   #1
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Rep: Reputation: 36
Help needed to run simple java program in linux


Hi guys ,
This is the first time i m running java application inside linux.

i have installed jdk-6u20-linux-i586-rpm.bin jre-6u20-linux-i586-rpm.bin in my linux machine.

and set JAVA_HOME and JRE_HOME variables respectively.
Quote:
# echo $JAVA_HOME
/usr/java/jdk1.6.0_20/
# echo $JRE_HOME
/usr/java/jre1.6.0_20/
I have created a little java program helloworld.java
Quote:
class helloworld{
public static void main(String[] args) {
System.out.println("Hello World!"); // Display the string.
}
}
I m able to compile the program by doing javac helloworld.java
but not able to run the program by doing java helloworld.
It is giving me following error.
Quote:
Exception in thread "main" java.lang.NoClassDefFoundError: helloworld
at gnu.java.lang.MainThread.run(libgcj.so.7rh)
Caused by: java.lang.ClassNotFoundException: helloworld not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/usr/java/jdk1.6.0_20/bin/], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.7rh)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at java.lang.ClassLoader.loadClass(libgcj.so.7rh)
at gnu.java.lang.MainThread.run(libgcj.so.7rh)
whenever i type java in command prompt it give me following output. M i missing anything.
Quote:
# java
Usage: gij [OPTION] ... CLASS [ARGS] ...
to invoke CLASS.main, or
gij -jar [OPTION] ... JARFILE [ARGS] ...
to execute a jar file
Try `gij --help' for more information.

Last edited by pinga123; 05-05-2010 at 11:57 PM.
 
Old 05-05-2010, 11:55 PM   #2
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
I think /usr/bin/java is not poited to /usr/java/jdk1.6.0_20/bin/java
It is pointed to some other java (which i m not sure).

How do i change this pointing?
If i do the changes will it have any serious impact ?
 
Old 05-06-2010, 01:30 AM   #3
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2016 CentOS6.9 CentOS7.3 + 50+ other Linux OS, for test only.
Posts: 16,625

Rep: Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266
Why not use a package meant for your OS ? EL5 or CentOS 5.x ?
(Please add info about the Linux used, for every question.!)

This package, jdk-1.6.0_20-fcs.i586.rpm is for all el5,
and was created by "CERN Scientific Linux"
http://ftp.scientificlinux.org/linux...0-fcs.i586.rpm
http://ftp.scientificlinux.org/linux/scientific/54

The command : 'java -version' will tell which setup you have.

The version can be changed with the commands : 1) su
2) /usr/sbin/update-alternatives --config java
(But the rpm package install will usually do the setup.)
..
EDIT /sbin/... to /usr/sbin/...

Last edited by knudfl; 05-06-2010 at 05:50 AM.
 
Old 05-06-2010, 01:34 AM   #4
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by knudfl View Post
Why not use a package meant for your OS ? EL5 or CentOS 5.x ?
(Please add info about the Linux used, for every question.!)

This package, jdk-1.6.0_20-fcs.i586.rpm is for all el5,
and was created by "CERN Scientific Linux"
http://ftp.scientificlinux.org/linux...0-fcs.i586.rpm
http://ftp.scientificlinux.org/linux/scientific/54

The command : 'java -version' will tell which setup you have.

The version can be changed with the commands : 1) su
2) /sbin/update-alternatives --config java
(But the rpm package install will usually do the setup.)
..
My linux machine.
Quote:
LSB Version: :core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: EnterpriseEnterpriseServer
Description: Enterprise Linux Enterprise Linux Server release 5.2 (Carthage)
Release: 5.2
Codename: Carthage
 
Old 05-06-2010, 01:44 AM   #5
kirukan
Senior Member
 
Registered: Jun 2008
Location: Eelam
Distribution: Redhat, Solaris, Suse
Posts: 1,274

Rep: Reputation: 148Reputation: 148
Quote:
To compile
#javac helloworld.java

To run
#java helloworld
isn't it? No error return because i am using same jdk-1.6.0_20
and just setup JAVA_HOME path in /etc/profile as JAVA_HOME = /usr/java/jdk-1.6.0_20

Last edited by kirukan; 05-06-2010 at 01:49 AM.
 
Old 05-06-2010, 05:00 AM   #6
pinga123
Member
 
Registered: Sep 2009
Posts: 684
Blog Entries: 2

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by knudfl View Post
Why not use a package meant for your OS ? EL5 or CentOS 5.x ?
(Please add info about the Linux used, for every question.!)

This package, jdk-1.6.0_20-fcs.i586.rpm is for all el5,
and was created by "CERN Scientific Linux"
http://ftp.scientificlinux.org/linux...0-fcs.i586.rpm
http://ftp.scientificlinux.org/linux/scientific/54

The command : 'java -version' will tell which setup you have.

The version can be changed with the commands : 1) su
2) /sbin/update-alternatives --config java
(But the rpm package install will usually do the setup.)
..
i dont have /sbin/update-alternatives what shall i do?
 
Old 05-06-2010, 05:40 AM   #7
PMP
Member
 
Registered: Apr 2009
Location: ~
Distribution: RHEL, Fedora
Posts: 381

Rep: Reputation: 58
The error here is NoclassDefFound

Go to the directory where you helloworld.java is present.
execute
Code:
javac helloworld.java
If this is successful you will see a file called helloworld.class in the same directory

Now do

Code:
java --classpath . helloworld
 
Old 05-06-2010, 06:25 AM   #8
knudfl
LQ 5k Club
 
Registered: Jan 2008
Location: Copenhagen, DK
Distribution: pclos2016 CentOS6.9 CentOS7.3 + 50+ other Linux OS, for test only.
Posts: 16,625

Rep: Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266Reputation: 3266
Sorry ... it's /usr/sbin/

... Continued in this parallel pinga123 thread ..
http://www.linuxquestions.org/questi...nd-jre-806269/

..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to compile and run a java program in linux !!!! jmax24 Programming 7 08-06-2010 03:56 AM
How to run Linux commands using a Java program? aparna.v Linux - Newbie 2 04-09-2010 09:37 AM
Run sample java program on jpcap in linux Nadishka Linux - Software 5 10-29-2009 01:37 AM
how to run linux command from java program? ranger225 Linux - Newbie 1 11-10-2004 06:55 AM
java, simple program help needed.. marlor Programming 1 11-04-2004 02:40 PM


All times are GMT -5. The time now is 12:03 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration