mitch
mitch

Reputation: 2245

Java, Mac OS, Windows and Linux

I have migrated from Linux (Ubuntu) to Mac OS. I have wrote an application in Java (swing). I have run it successfully the same code in windows and linux but in mac os I have some problems.

Here is the code and problems in comments:

public MainForm() {
    setResizable(false);
    setAutoRequestFocus(false); // This method is undefined for type MainForm
    initComponents();
}

Another:

Object[] industries = jList1.getSelectedValuesList().toArray(); //  This method is undefined...

And the last one:

setType(Type.UTILITY); // Type can't be resolved as variable

Of course I can't compile it.

Java versions: Ubuntu:

java version "1.7.0_07" Java(TM) SE Runtime Environment (build 1.7.0_07-b10) Java HotSpot(TM) Server VM (build 23.3-b01, mixed mode)

MacOS:

java version "1.6.0_35" Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811) Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)

I can't update java (because It seems to be the newest version for mac). I want to develop this app on mac now.

Upvotes: 0

Views: 3782

Answers (2)

Brian
Brian

Reputation: 17299

After doing some digging for the methods giving you problems, it's clear you're not running the same JDK on every platform. Specifically, your Windows and Linux boxes are running JDK 1.7, and your Mac OS X box is running JDK 1.6 or older. See this question for using JDK 1.7 on Mac.

The fact remains that you don't need to compile your application on every platform. Java is a "compile once, run everywhere" language. The bytecode produced by the compiler works for every platform, regardless of which platform compiled it, so long as you didn't introduce any system dependencies in the code yourself.

In other words, Java itself is platform-agnostic as long as your code is platform-agnostic. Your problem is just a JDK version error, so upgrading your Mac's version of the JDK to 1.7 will fix this.

Note that you can't run binaries compiled with a 1.7 source target in Java 6 or lower. You can change the source target to 1.6 on compile time, but this will preclude you from using the Java 7 API (such as the getSelectedValuesList method).

Upvotes: 2

Ilya
Ilya

Reputation: 29663

Create executable jar on Linux, and execute it on Mac. It should works well.
If you want develop your app on another OS, then check that JDK has same version.
Full version should be equals. 1.6_31 hould be equals too

Upvotes: 1

Related Questions