Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: XCODE: Compiling in older release of Java?



On Sep 7, 2008, at 06:24, Gary Bradshaw wrote:

I'm compiling Java Applets that do not use the latest features of Java, mostly because not all browsers have the latest version of Java available.  I can't find a way to specify in XCODE that I want to use
version 1.3 rather than the latest and greatest.  Any help would be
greatly appreciated.

Caveat: I have a highly customized Xcode environment because the projects I work on, and the ant scripts they use, are fairly complex. So everything I say below needs to be vetted. There may be easier ways to do what you want. I'm just speaking from my own personal experience.

You might be out of luck with trying to support Java 1.3 (but see below) because Leopard doesn't even support Java 1.3. Tiger might, but not 100% sure. But you should start by asking yourself if you really need to support Java 1.3. Java 1.3 was a particularly bad version of Java, as I recall. I would be surprised if even a small percentage of your intended customer base is still running Java 1.3. And if they are, they should upgrade.

With the newer versions of Xcode, at least 2.5, 3.0, and 3.1, the build.xml file that Xcode generates for you when you create a new Java Project (I used the Java Tool project as a reference, other types might be different), contains the following for the Ant compile target:

<target name="compile" depends="init" description="Compile code">
    <mkdir dir="${bin}"/>
    <javac deprecation="on" srcdir="${src}" destdir="${bin}"
               source="1.3" target="1.2"
               includeAntRuntime="no"
               classpathref="lib.path" debug="${compile.debug}">
    </javac>
</target>

As you can see with the source="1.3" and target="1.2" arguments, it already (attempts to) default to Java 1.3/1.2. But this will not really build your app against the Java 1.3 libraries. It will still use whatever your default Java is (most likely Java 1.5) to build against. This can result in building class/jar files which will be recognized by the targeted JVM, but not actually runnable (or not run properly) by that JVM, due to references to newer Java API's which did not exist in the targeted JVM's libraries, but which were not caught at compile time because you're actually building with a newer version of Java.

I haven't tried this, but if you could get hold of the Java 1.3 libraries somewhere (not sure if Sun still even offers them), then you might be able to get what you want by specifying the bootclasspath option of the ant javac command and referencing those Java 1.3 libraries.

But like I said above, you really need to ask yourself if you need to support Java 1.3. It gets a little easier if you decide to make Java 1.4 your cut-off since OS X Leopard and Tiger both have Java 1.4.

The easiest way I have found to target a specific JVM is to set the JAVA_HOME environment variable in your Xcode Target. This is the *Xcode* Target, not one of the ant targets. In the Xcode IDE on the left, you'll see "Targets", and your project should already have a default target in there that's named the same as your project. Double-click on that target and you'll be shown a window that you can use to configure some build-related settings. By default, Xcode creates two types of configurations, Debug and Release (these are in the drop-down in the upper left). For Java builds, there is really no distinction here. Xcode does define a few extra "Build Settings" for Debug vs. Release, but whether or not debug information is included in the built class/jar files depends on additional settings passed into the ant javac command (debug and debuglevel), not anything set in the Xcode Target.

Setting that aside, you should be able to click on the plus (+) button under the Build Settings section in the default Xcode Target and add the following:

JAVA_HOME = /System/Library/Frameworks/JavaVM.framework/Versions/1.4.2/Home

If you keep both the Debug and Release configurations, make sure you do this for both of them in case you accidentally build with one when you think you're building with the other because, like I said, there is no practical difference between the two when building Java. Or better yet, create your own configurations, but that's another email.

This will set the JAVA_HOME environment variable that ant will use when it builds your project, and will specifically use the Java 1.4 libraries. To be safe, you should also change the source="1.3" and target="1.2" values in the ant javac command to 1.4 so you don't end up creating class/jar files that can be recognized by older JVM's, but may not run properly if you happen to use Java 1.4+ specific API's that didn't exist in those old JVM's.

Hope this helps.

Rob

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >XCODE: Compiling in older release of Java? (From: Gary Bradshaw <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.