Help needed to run simple java program in linux


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help needed to run simple java program in linux
# 1  
Old 05-06-2010
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.
Code:
# 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
Code:
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.
Code:
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.
Code:
# 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.

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 ?

Last edited by pludi; 05-06-2010 at 02:02 AM.. Reason: [code] (#), not [quote]
# 2  
Old 05-06-2010
# 3  
Old 05-06-2010
Quote:
Originally Posted by itkamaraj
Thanks for the reply but in my case it is pointing to different java version.
whenever i do java -version it shows 1.4 .

But i have installed the latest one.

It should have shown something like 1.6.
# 4  
Old 05-06-2010
check out my classpath and path variable values

Code:
kamaraj@kamaraj-laptop:~/Desktop/testing$ echo  $PATH
/home/kamaraj/Desktop/jdk1.6.0_10/bin:.:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/opt/real/RealPlayer
kamaraj@kamaraj-laptop:~/Desktop/testing$ echo  $CLASSPATH
/home/kamaraj/Desktop/jdk1.6.0_10/lib:.
kamaraj@kamaraj-laptop:~/Desktop/testing$ echo $JAVA_HOME
/home/kamaraj/Desktop/jdk1.6.0_10
kamaraj@kamaraj-laptop:~/Desktop/testing$ java -version
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)
kamaraj@kamaraj-laptop:~/Desktop/testing$

# 5  
Old 05-06-2010
What should i do now?
# 6  
Old 05-06-2010
# 7  
Old 05-07-2010
Now its working.
Here is what i have done(Correct me if it is wrong)

i have fired "which java" command.

from the output i have got the location of java file
i changed the java file location from /usr/bin
to /usr/bin/javabackup (created new folder named javabackup).
added /usr/java/jdk<versionname>/bin to path using.
export PATH=$PATH:/usr/java/jdk1.6.0_20/bin/

Now its working file.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to run simple single command on multiple Linux servers?

Hi All, How can i run a single command on multiple servers with or without giving credentials. I have a file(servers.txt) which has got list of servers and i want to run a command lsb_release -dr on all these servers and get output of those servers against each server. I tried below code... (9 Replies)
Discussion started by: darling
9 Replies

2. Shell Programming and Scripting

Simple if statement help needed please

if ]; then echo "successssssssssssssssssss" $filename = "<font color='red'>$i</font>" else echo "failureeeeeeeeeeeeeeeeeeeee" $filename = "$i" fi; I'm just trying to see is this - read a file name and highlight... (2 Replies)
Discussion started by: vmanda
2 Replies

3. UNIX for Advanced & Expert Users

java compile and run program help

What is the trick to get a java program to run and compile? I can't even get a basic skeleton to run and compile. What packages do I need? I figured the java-gcj and gcc-java packages was enough. Do I need any other packages? I thought I had to do this and it would work but its not. javac... (1 Reply)
Discussion started by: cokedude
1 Replies

4. Programming

Running a Java program on Linux

Hello, I have a project directory in /home/researcher I have in my project/src three packages:A (contains the main class), B and C and I have 2 jar-files file1.jar file2.jar files in the project/my-jars In Class A I import other classes from the other packages I compiled as follows:... (4 Replies)
Discussion started by: chercheur857
4 Replies

5. Debian

Change the privileges needed to run a program

Hi everyone, I have an issue with a project of mine. I have to run a program on a terminal which requires to be logged in as su to have it run it. Given that I'm having problem to use expect to give the password I'd like to change the privilege of that program from SU to normal user ( I have the SU... (13 Replies)
Discussion started by: gaisselick87
13 Replies

6. AIX

Unable to run a simple threaded program on AIX

Hi, I am unable to run a simple C++ threaded program on the AIX 5.3 platform. It says exec(): 0509-036 Cannot load program ./sendClient because of the following errors: rtld: 0712-001 Symbol __pthread was referenced from module sendClient(), but a runtime definition of the... (6 Replies)
Discussion started by: asutoshch
6 Replies

7. Shell Programming and Scripting

Executing a Java Program

I am entirely new to shell scripting and would like to create a script to execute a java program called Main. I've already compiled it and placed the .java and .class files at /root/javaTest. Next I made a shell script that simply contained: java /root/javaTest/Main . I made the script... (2 Replies)
Discussion started by: hypnotic_meat
2 Replies

8. Shell Programming and Scripting

how can i run java program from any where

Hello all sorry didnt know where to post it i compiled simple program that using "System.getProperty("user.dir");" now i compiled the program under directory foo and and its running great when i do "java myapp" i included this directory in the $PATH env variable so i could see it fro any where... (1 Reply)
Discussion started by: umen
1 Replies

9. Shell Programming and Scripting

simple script help needed

I am relatively new to *nix and have set up a small home network with a red hat server, what i would like to do is write a small script to check to see if a computer is connected by using the ip address of the computer. can get the ping to return but cant get the echo line working. the output i... (3 Replies)
Discussion started by: nobius
3 Replies

10. Programming

Communication between a java and c++ program

Hi, I have the following problem. I have 2 programs, a java program and a c++ program. These 2 programs have to communicate with each other in full duplex mode. I want to use pipes for this communication. So when the c++ program pust something on the stdout the java program must be able to read... (4 Replies)
Discussion started by: lmnt22
4 Replies
Login or Register to Ask a Question