Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will Java compiled in windows work in Linux?

My Java program is in working order when i use it under Windows(Eclipse and Bluej). I compress it to a Jar and send it to my red hat and bang. nothing works. It breaks on the weirdest things, such as text field set text will not show, JPasswordfield just disappeared, Java AWT ROBOT dies too... the list goes on, first i thought it must be my Linux JRE is out of date, but i installed latest JRE then the JDK with no improvement at all. I have a feeling that i miss understood the Java cross plat ability. I also tried to remove all of my functions and guts to see what is breaking but it seems every second thing is breaking, other than the some of the major GUI components and most of the back end stuff. basically any thing that uses some thing fancy will blowup in my face, such as making a text field in to a password field...

This is my first time posting ;) please be nice to the newbie!

Thanks!!!

SOLVED!!! Yay. Problem solved!!! It was because my Java path isn't set, so my GCC/GCJ jumped in instead of my oracle java, even tho i used java -jar xxx.jar. so I put in the java directory path from of my java -jar xxx.jar and worked like a charm. unless you set the path, you have have to do this manually

/usr/java/jdk1.6.0_21/jre/bin/java -jar xxxxx.jar

java -version to check if your real java is running or if it s still GCJ

like image 480
JavaLu Avatar asked Oct 08 '10 16:10

JavaLu


People also ask

Is Java compatible with Linux?

Java on Linux PlatformsThis installs the Java Runtime Environment (JRE) for 32-bit Linux, using an archive binary file ( . tar. gz ) that can be installed by anyone (not only the root users), in any location that you can write to. However, only the root user can install Java into the system location.

Does Java work cross platform?

Java is cross platform because a program's source code is compiled into an intermediate "bytecode" language. The bytecode is then executed by a Java Virtual Machine (Java interpreter) that was written for that particular hardware platform.

Is Java faster Windows or Linux?

can you elaborate more differences @Joachim Sauer,I had a similar interview question asked once. I don't know why, but in fact Java runs way faster on Linux than on Windows. Compiling an Hybris project on Linux (Ubuntu mate 16.04) took 1/4 of the time required on Windows 10 and 1/2 for server start up.

What OS can Java run on?

An overview of the software development process. Because the Java VM is available on many different operating systems, the same . class files are capable of running on Microsoft Windows, the Solaris™ Operating System (Solaris OS), Linux, or Mac OS.


2 Answers

Yes. The class and jar formats are intentionally crossplatform.

Are you absolutely certain that your jar file was copied correctly to your Linux machine? If you used ftp, it is crucial to use binary instead of ascii transfer.

like image 103
Thorbjørn Ravn Andersen Avatar answered Oct 25 '22 13:10

Thorbjørn Ravn Andersen


Linux users often run java programs with gcj instead of java. Check that you use a correct executable.

like image 42
Ha. Avatar answered Oct 25 '22 14:10

Ha.