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 bu开发者_StackOverflowt 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
Linux users often run java programs with gcj instead of java. Check that you use a correct executable.
Check that you are using Sun's (Oracle's) JRE on your Linux machine and not some 3rd party Java implementation such as gcj or the likes.
In my experience, Java applications are quite portable as long as you stick to the same JVM/runtime vendor on every target SO, but Java implementations from different vendors might behave different from each other.
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.
Is your application dependent upon any external libraries that you also need to have available on your Linux machine?
Java says: "Write once, run anywhere".
Swing should be fully portable. Try using the metal look and feel, which is widely supported. I have my doubts about java.awt.Robot
though and wouldn't be suprised if this was the source of your problems.
Are you using KDE? Which theme? I had an issue yesterday that the theme "Cleanlooks" has a lot of bugs rendering widgets. Try "Oxygen".
If you can, try the code on a different Linux box (maybe it has a hardware defect). Run "memtest" (should be an option in the boot loader or on your rescue CD).
I have a Swing app which I distributed via Java Web Start that I haven't updated since 2004 which I know still works fine on Mac OS X, Windows, and Linux. I ran it just the other day because somebody emailed me a question about it. It was originally written on Windows but has never shown any problems on other operating systems or even in much much later versions of Java.
The JVM presents a very level playing field across a wide variety of platforms and the Java API is well implemented to work the same and offer the same functionality. My bet is that you will find this problem is something entirely unrelated to your Java code. In addition to the suggestion to try your app on another machine running the same OS, be sure to try other people's Java apps running on the one which is giving problems. Try my own HotSheet: http://www.johnmunsch.com/projects/HotSheet/ or a game like Legerdemain: http://roguelikefiction.com/?page_id=6 to see if those will work.
On linux it might be crucial to use the Sun JDK/JRE and not the openjdk, which is an implementation of the official sun java jdk. So it could be that, though not sure at all.
Java is very transportable. Chances are your VM is different. Although the Open Source VMs are getting very good, I recommend trying with Sun's VM--I've never had a problem with it running any code.
Also, if you are using any libraries with machine language components, those will have to be different (I've noticed this with some graphics libraries that call through to the platform's 3d subsystem)
But Java itself WILL port easily to any system that has the same libraries and a good VM Very Well--I do it all the time and have been doing so for ten years and literally have never had a problem. This is running client/server systems where the clients and server were on different platforms, PC/Mac & Unix and even embedded systems--stuff just ports.
Now, applets running in different browsers, or visually trying to match fonts on machines that don't contain the same font--Nothing will help you there.
精彩评论