Tags: apis, consideration, core, create, follows, java, javaprog, program, programto, special, unix, windows-nt
Java under UNIX v/s Windows-NT
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 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,
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,
4. Run the following command,
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. How do you set PATH & CLASSPATH in UNIX.
5. 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
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.
Leave a comment...
- 8 Comments
You don't need to recompile for Unix. You cannot specify the .class extension.
Put the JavaProg in a directory (ie /your/directory). From /your/directory, run java as follows:
java -cp . JavaProg
the "-cp ." specifies that the CLASSPATH should be from the current directory. Don't confuse "CLASSPATH" with the Unix "PATH" variable.
Btw, you do have to consider things like security issues when bringing Java applications to Unix. I don't think Unix, in general, will allow you to open sockets without configuring the JVM in some way.#1; Fri, 29 Jun 2007 02:16:00 GMT
Btw, you don't need to worry about the "PATH" unix variable, since it looks like java is indeed running (ie your PATH variable currently has the java executable in it) it's just not finding the class file. Setting the "PATH" unix variable is different for every shell type.
setenv PATH $PATH:/another/path
(or something like that)#2; Fri, 29 Jun 2007 02:16:00 GMT
- As in the crosspost (to the JVM forum) your classpath is wrong. #3; Fri, 29 Jun 2007 02:16:00 GMT
I'm still learning java programming on a Linux box. I think the only problem is CLASSPATH(of course you have to have same JVM on both platforms). As long as you set the right value, there should be no other things to do to run a class file on UNIX platform., which is compiled within other OSs.
As for the socket, I can't see any problem with opening one. Can you explain more? Thank you.
Liheng#4; Fri, 29 Jun 2007 02:16:00 GMT
- My Unix JVM threw SecurityExceptions at me. Basically, it comes down to starting the JVM with a policy file that specifies permissions. Check out the SocketPermission class. #5; Fri, 29 Jun 2007 02:16:00 GMT
- Would there be a considerable change that needs to be done when porting server-side applications such as sockets-EJB-servlets from WinNt to Unix? If for example, the application will be developed under WinNT-WebLogic Server 6.1 and be deployed on Unix-Weblogic Server 6.1? #6; Fri, 29 Jun 2007 02:16:00 GMT
- And also what would be the precautions to look out for in when writing the code? Any other information is appreciated. Thanks. #7; Fri, 29 Jun 2007 02:16:00 GMT
- What about using SWING in Unix? How do you run your java applications that extend JFrame? Can it run on Unix? #8; Fri, 29 Jun 2007 02:16:00 GMT