Java version optimization
Java version optimization
- Subject: Java version optimization
- From: Freek Dijkstra <email@hidden>
- Date: Fri, 14 May 2004 01:20:35 +0200
Hi,
I have a problem trying to write code that is optimized for java 1.4 with
Xcode. I hope some people can get me on my way. Replies to the java-dev list
or me directly, to avoid cross-posting.
First of all, I'm using Java for a Cocoa project, and needed a piece of code
to copy a file. Now, there are two ways to do this in Java (NSFileManager is
Objective-C only): just using java.io.* tools, use a buffer and copy using
the buffer. For SDK 1.4 and higher, you can use so-called channels in
java.nio.channels. At least, that's what I found on the way, being a newbie.
I succesfully wrote a piece of code which first tried using channels, and if
that fails reverted to the slower method. This works when I use javac in the
commandline, and for both java142 and java131 (as found in
/System/Frameworks/JavaVM.framework. Indeed, for java 1.3.1, the slower
method is used).
Now, when I try this in Xcode, I get the following Exception while executing
the code in my Cocoa project:
java.lang.SecurityException: Prohibited package name: java.nio.channels
at java.lang.ClassLoader.defineClass(ClassLoader.java:474)
I'm surprised, because I did not get this when just using javac.
According to sources on the web, this is because -apparently- the
application created with Xcode uses Java 1.3 to execute the code, and does
not know about the channel classes. If I understand correctly (do I? please
confirm or deny), the SecurityException is thrown because Java thinks I'm
adding these classes to java.*. First of all, why do I now get this
exception, instead of the NoClassDefFoundError I expected (which I got when
trying java131).
Looking at my Target's Java Compiler Settings, the "target VM version" was
set to "unspecified" (which defaults to 1.2) and the "soyrce version" was
set to "unspecified" (which defaults to 1.3). Setting these two values to
1.4, I get this weird error when I run my application:
2004-05-14 00:15:11.652 Glider Edit[3434] Unknown class `MyAppAppDelegate'
in nib file, using `NSObject' instead.
Now I'm baffled. All I changed was the target and source version of Java!!
The build transcript does indeed show that the compiled class
MyAppAppDelegate.class is added to the jar file. What is the cause of this
error?
In addition, I have the impression that this is not what I want, because I
set my target to 1.4, and I want it to be backward compatible. Am I messing
with the wrong parameters??
OK, so I don't understand anymore: how to I optimize my code to use java 1.4
features on Mac OS X.3 and to use java 1.3 features on Mac OS X.2?
I'm very interested in any pointers and sample code!
Thanks!
Freek Dijkstra
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.