Cannot run this .java file from the home directory??


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Cannot run this .java file from the home directory??
# 1  
Old 07-30-2013
Cannot run this .java file from the home directory??

I wrote a simple test.java program in vi. I know it compiles correctly because I went into the directory where test.java was and compiled it and it created a java.class. I then ran test.java by staying in the same directory where it was and it worked great.

However, when i backed out of the directory to the home directory I typed the following and it did not run test.java. Why not? I specified the path in the most direct way possible.

Code:
┌─(shaneyost@Shanes-MacBook-Pro-2:s000)───────────────────────────────────────────────────────────────────────────────────────────(~)─┐
└─(1:19:31:%)── java ./java_programs/test_program/test.java                                                         ──(Tue, 20130730)─┘
Exception in thread "main" java.lang.NoClassDefFoundError: //java_programs/test_program/test/java
Caused by: java.lang.ClassNotFoundException: ..java_programs.test_program.test.java
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

This was when I was in the directory where test.java and test.class was. It worked.
Code:
┌─(shaneyost@Shanes-MacBook-Pro-2:s000)────────────────────────────────────────────────────────────────(~/java_programs/test_program)─┐
└─(19:29:%)── java test                                                                                             ──(Tue, 20130730)─┘

# 2  
Old 08-01-2013
Try: java ./java_programs/test_program/test

without the .java extension like you had
This User Gave Thanks to MR.bean For This Post:
# 3  
Old 08-01-2013
Also ensure the CLASSPATH is set to the directory where your .class files are created.
This User Gave Thanks to krishmaths For This Post:
# 4  
Old 08-01-2013
thanks both suggestions made it work like a charm
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Solaris

SunOS confusing root directory and user home directory

Hello, I've just started using a Solaris machine with SunOS 5.10. After the machine is turned on, I open a Console window and at the prompt, if I execute a pwd command, it tells me I'm at my home directory (someone configured "myuser" as default user after init). ... (2 Replies)
Discussion started by: egyassun
2 Replies

2. UNIX for Dummies Questions & Answers

Duplicated file names with home directory symbol appearing in ls .

Why are there duplicated file names listed when I execute ls ? Result of my ls /root/Desktop : aaa ca new file~ what what~ Thanks. (4 Replies)
Discussion started by: Hijanoqu
4 Replies

3. Shell Programming and Scripting

Looking for config file in home directory first??

hi, i have written a shell script inside which i am using a pgp command to encrypt a file. when pgp command is run , there is a /.pgp/pgp.cfg file in my home directory. i logged into the unix server with my userid, when i run the script from the command prompt, pgp is successful, since i am... (5 Replies)
Discussion started by: Little
5 Replies

4. Shell Programming and Scripting

How to run the Shell Script from external directory using java?

Hi, I have created a Shell Script and invoke through java using Process Builder It's working fine, if (Shell script file ) in the same directory as java file. By Problem: How to run the Shell Script file( resides in external directory) using java. What configuration i have... (1 Reply)
Discussion started by: nanthagopal
1 Replies

5. Shell Programming and Scripting

rename all file with blank in directory from home root , please help me

hi , :wall: I've in directory home user 3 file with blank space in name file, I would like erase the all character that no have alphanum more dot in namefile from home root , below the script. If I execute the shell script from directory where stay it's execute well done.But I would like... (1 Reply)
Discussion started by: giankan
1 Replies

6. UNIX for Dummies Questions & Answers

How to get the latest modified file name in /home directory?

I only know how to list all sub-directories or files in specified directory. I don't know how to order them by modified date, furthermore, I don't know how to get the top one file in the sorted list. Wish you can do me a favor. Thanks in advance! (3 Replies)
Discussion started by: crest.boy
3 Replies

7. UNIX for Dummies Questions & Answers

Trying to run java file in crontab

Hi. I have a java program that create reports, and I would like to run it at each hour using crontab. The main file is crome.jar located at /WebApps/Crome folder. When I want to execute the program I use the next script (name crome): #!/bin/sh if ; then ... (1 Reply)
Discussion started by: karmariv
1 Replies

8. UNIX for Dummies Questions & Answers

run a java file on UNIX?

HI, I want to run my .java file on a SunOS 5.8 Unix machine. The java file is writen with Ready to Program (Similar to Jbuilder) on a PC. Thanks!! (3 Replies)
Discussion started by: leotopia
3 Replies

9. UNIX for Dummies Questions & Answers

Searching a file withoug leaving home directory!!

hello there ! I am in my current working directory, and i want search a file in "dev" directory which is under root(/), but i donot want leave my current working directory. is it possible to find file like that ? let us say i am in /home/bin/user/malik/abid directory and i want find a file... (2 Replies)
Discussion started by: abidmalik
2 Replies
Login or Register to Ask a Question