views:

364

answers:

10

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

+4  A: 

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.

Thorbjørn Ravn Andersen
If this was a binary/ascii problem, the .jar file wouldn't even be readable as valid. Nothing would work at all.
Erick Robertson
i used total commander to FTP, i can't test right now as i am Away from my box. don't know if it was ftp or ascii, but i will try using my Mem stick.
JavaLu
That depends on the bit patterns present in the file transferred.
Thorbjørn Ravn Andersen
@JavaLu, you can also transfer the _source_ files and compile them on your Linux machine. You will need the JDK installed.
Thorbjørn Ravn Andersen
mm kk. will do that
JavaLu
+2  A: 

Is your application dependent upon any external libraries that you also need to have available on your Linux machine?

Dave
If this was the problem, there would be ClassDefNotFoundExceptions being thrown all over the place.
Erick Robertson
True, but we don't have much to go on other than a vague "it's broken."
Dave
er, i am away from my box so i can't recall all the errors. i do remember one of them tho: java.lang.error: not implemented.sorry for not being prepared, i was expecting 5 hours before the first reply and less intense.
JavaLu
+1  A: 

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

Aaron Digulla
A: 

Java says: "Write once, run anywhere".

卢声远 Shengyuan Lu
When it comes to Swing it's actually more like "Write once, test everywhere"
finalman
*Write once, run anywhere* is actually more true for C than for Java. Java is supposed to be **compile** *once, run anywhere that has a JVM*.
Ben Voigt
note that WORA doesn't apply to native methods/libs
Colin Hebert
Bill K
+1  A: 

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.

Qwerky
+7  A: 

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

Ha
oh i am actually using gcj -jar xxx to run my Jar
JavaLu
@JavaLu: I think that's your problem right there. On Linux, you should use either OpenJDK, or Sun's Java.
Mike Baranczak
Yep, thats the answer alright. Thanks guys!!!!
JavaLu
+1  A: 

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.

John Munsch
+3  A: 

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.

Grodriguez
I see, I am using gcj to run my Jar. I have oracle installed jre but not sure whats the command to run the jar.
JavaLu
`java -jar JarName` :-)
Grodriguez
BTW you can use `which java` to find out which java command is actually being invoked.
Grodriguez
A: 

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.

Bill K
+1  A: 

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.

toomuchcs