Java under UNIX

Is there any special consideration for a Java Program

to work under UNIX.

My problem is as follows,

I have a Java program say "JavaProg.java".

I create its class file under Windows-NT i.e.

"JavaProg.class" after compiling the java code using

the command "javac JavaProg.java".

Everythings perfect till here. The class file generates

output as expected under Windows-NT

Problem starts when I transfer that class file to UNIX.

With the initial promise of Java as "Write Once,

Run Everywhere" I just take the class file and put

it in my directory under UNIX.

i.e. home/myfiles/javacodes/programs

I set the PATH as "/home/java/bin" & CLASSPATH variable

as "/home/java/lib" since these are the directories where

the java.exe executable and the library files are existing.

Then when I execute

"java JavaProg" from my homedirectory of home/myfiles/javacodes

/programs it gives the following error,

Can't find the class file JavaProg

So I try out various other options like

"java JavaProg.class" (Specifying the .class extension)

on which it says

Invalid class name JavaProg.class

So I try,

"java /home/myfiles/javacodes/programs/JavaProg.class"

on which it says

Error finding class JavaProg.class : Wrong Name

=======================================================

Under Windows-NT I just have to do the following 4 steps,

1. set PATH=.;c:\jdk1.1.8\bin

2. set CLASSPATH=.;c:\jdk1.1.8\lib

3. Run the following command,

"javac JavaProg.java"

4. Run the following command,

"java JavaProg"

=======================================================

My Questions,

1. Are there any special considerations when class files

are placed under UNIX.

2. Does the above for Windows-NT apply exactly the same manner

in UNIX too. Or is there some additional thing to be done.

3. Are there any environment variables to be set under UNIX

which I might be missing.

4. Does the Java code have to be recompiled under UNIX.

I personally feel "NO" since Java promises "Write Once,

Run Everywhere" theme. So the same class file should even

work under UNIX even though it was intially compiled using

Windows-NT.

Can someone please respond as early as possible as I am

close to the project deadline. Any help appreciated. Thanks

in advance to any help, insights, views, ideas anyone can

throw on this subject.

Thanks,

Jatin

[2716 byte] By [Jatin2000] at [2007-9-26 1:33:43]
# 1

your Classpath unde Unix should look like this:

CLASSPATH=.:/home/java/lib

you have to add the leading "." for the current directory you are in to be included in the classpath.

Then you have to call

java JavaProg instead of java JavaProg.class

1. Class-files must be in your current class path else the vm won't find them

2. you may set the environment variables under unix (if you are using bash or sh) by

export PATH=.:/home/java/bin:$PATH

if you are using java 1.1

export CLASSPATH=.:/home/java/lib

else if you are using e.g. jdk1.3 find the "rt.jar" file and

export CLASSPATH=.:/path_to_rt_jar/rt.jar

3. Usually you don't need more environment variables

4. No, if the classes are transferred binary (important, as windows ftp transfers files as ascii text by standard changing some characters!) there should be no recompilation necessary. At least, if the virtual machines are not too different in their version.

tbraun at 2007-6-29 2:15:52 > top of Java-index,Archived Forums,Java Programming...