Will Java compiled in windows work in Linux?

依然范特西╮ 提交于 2019-12-05 01:48:02

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".

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).

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!