Java under UNIx

Hi

I have some problem executing class file under UNIX.

I have a directory under UNIX,

/home/user1

wherein I have placed a class file say "JavaProg.class"

I execute "java JavaProg" from the above directory

and it generates the desired output.

Now, I have another directory,

/home/user2

wherein I again I have placed the same class file "JavaProg.class"

I execute "java JavaProg" from this second directory

this time and it again generates the desired output.

Problem starts now,

I delete the class file from /home/user2

1. And then I execute the following command trying to

directly execute class file which is available from user1's directory (since user2 class file is deleted)

"java /home/user1/JavaProg" from "/home/user2"

directory. (since I am executing user1's class file

from user2 directory)

On this it says "Can't find the class file".

So I try various other options like.

2. First I set the CLASSPATH as

set $CLASSPATH=.:/home/user1:/opt/java/lib:$CLASSPATH

export CLASSPATH

And I try the following command

"java JavaProg" (This time I dont' write the complete

absolute path since its already defined in the CLASSPATH) I get an error. So I still try the following,

3.

"java /home/user1/JavaProg"

ERROR

4. "java -classpath .:home/user1 JavaProg

ERROr

5. "java -classpath .:home/user1 home/user1/JavaProg

ERROr

6. "java -cp .:home/user1 JavaProg

ERROr

7. "java -cp .:home/user1 home/user1/JavaProg

ERROr

What might be the source of the error. Can anyone

help. Thanks in advance for the help.

Thank,s

JAtin

[1860 byte] By [Jatin2000] at [2007-9-26 2:22:13]
# 1

> Hi

>

> I have some problem executing class file under UNIX.

>

>

> I have a directory under UNIX,

>

> /home/user1

>

> wherein I have placed a class file say

> "JavaProg.class"

>

> I execute "java JavaProg" from the above directory

> and it generates the desired output.

>

>

>

> Now, I have another directory,

>

> /home/user2

>

> wherein I again I have placed the same class file

> "JavaProg.class"

>

> I execute "java JavaProg" from this second directory

> this time and it again generates the desired output.

>

>

> Problem starts now,

>

> I delete the class file from /home/user2

>

> 1. And then I execute the following command trying to

>

> directly execute class file which is available from

> user1's directory (since user2 class file is deleted)

>

> "java /home/user1/JavaProg" from "/home/user2"

> directory. (since I am executing user1's class file

> from user2 directory)

>

> On this it says "Can't find the class file".

You should realize that the java command doesn't take a class file as an argument, it takes a class name. Since there is no class named /home/user1/JavaProg, you get an error.

>

>

>

> So I try various other options like.

>

> 2. First I set the CLASSPATH as

> set $CLASSPATH=.:/home/user1:/opt/java/lib:$CLASSPATH

> export CLASSPATH

I believe that should be:

set CLASSPATH=.:/home/user1:/opt/java/lib:$CLASSPATH

>

> And I try the following command

>

> "java JavaProg" (This time I dont' write the complete

>

> absolute path since its already defined in the

> CLASSPATH) I get an error.

> So I still try the following,

>

>

>

> 3.

>

> "java /home/user1/JavaProg"

>

> ERROR

That won't work for the same reason I stated earlier. The 'java' command expects a class name, not a class file as an argument.

>

>

> 4. "java -classpath .:home/user1 JavaProg

>

> ERROr

>

>

> 5. "java -classpath .:home/user1 home/user1/JavaProg

>

> ERROr

>

>

> 6. "java -cp .:home/user1 JavaProg

>

> ERROr

None of these will work because you've forgotten the leading '/' before 'home'.

>

>

> 7. "java -cp .:home/user1 home/user1/JavaProg

>

> ERROr

>

>

> What might be the source of the error. Can anyone

> help. Thanks in advance for the help.

How about trying:

java -cp /home/user1 JavaProg

Jim S.

Niceguy1 at 2007-6-29 9:28:30 > top of Java-index,Archived Forums,Java Programming...