Re: Java dev in XCode & CLASSPATH
Re: Java dev in XCode & CLASSPATH
- Subject: Re: Java dev in XCode & CLASSPATH
- From: David Ewing <email@hidden>
- Date: Fri, 16 Jul 2004 10:33:01 -0600
On Jul 14, 2004, at 5:37 AM, Brooke Smith wrote:
Dear Xcode-users,
I'm sorry to have to ask this but I've searched everywhere for an
answer: How do you get XCode to honor Java's $CLASSPATH (or similar)?
Xcode intentionally doesn't use CLASSPATH by default. If it did, it
would be very easy to get different build/run results depending on
whether you launched Xcode from Finder or Terminal. Xcode does,
however, provide some UI for configuring the classpath (which is done
separately for build time and run time).
I have created .class files that I have placed in a package that are
compiled correctly but aren't found at runtime when run under XCode
(but are under the command-line version of Javac/Java).
Here is a (slightly modified) copy of the post I posted at
http://forums.macrumors.com
http://forums.macrumors.com/showthread.php?p=916893#post916893
Note that I have upgraded to XCode 1.2 and it is still the same!
----
Dear all,
A previous post said that XCode defaults to finding .class files (and
.jars also?) in paths returned with:
javaconfig DefaultClasspath
javaconfig is used for legacy reasons, but we intend to remove its use
in the future. (You shouldn't count on it, or make changes to its
config file.) We consider its use an implementation detail in our build
system that is not for public consumption. ;-)
I am currently using XCode 1.1 and it would appear that these other
paths are only used by javac (the compiling arm) and not the java
runtime. I have created a package and saved it to /Library/Java (in the
DefaultClasspath). The build/compile process finds this OK, but when I
run the project the java.lang.NoClassDefFoundError error is returned.
Whatever javac is using, java isn't!
I can still run the command-line version - it of course uses
$CLASSPATH. I set my $CLASSPATH to include `javaconfig
DefaultClasspath`. I use javac to compile and it completes
successfully. I change CLASSPATH to NOT INCLUDE /Library/Java and then
try to execute the java app with java. The
java.lang.NoClassDefFoundError error is returned. This is the evidence
for me to say that in XCode (it appears that) the runtime doesn't use
the DefaultClasspaths.
So, the right thing to do is to add any .jar files you want to build
against to the project. They should end up in the Frameworks &
Libraries build phase of the target (which should happen
automatically). That takes care of the build side of things. For
running, you need to make sure they're found. How you do that depends
on what you're building.
If you're building an Application (a Mac OS X .app bundle), it's
easiest to add a Copy Files build phase, and copy the .jar files to
Resources/Java subdirectory of the bundle. You then need to add them to
the app's classpath. Do that by editing the "Pure Java" settings of the
target. Add the files to the Classpath list (you can use the
"$JAVAROOT" variable to refer to the Resources/Java subdirectory of the
bundle).
If you're creating a .jar file that can be run from the command line,
you need to add the .jar files to the command line of the executable.
Open the "java" executable and add a -classpath argument followed by
the colon-separated list of .jar files.
OK, there's one other way to add .jar files to the run time classpath.
You can merge their contents into the final .jar file. To do this you
just open the target and go to the Frameworks & Libraries build phase
and check the "Merge" checkbox next to the .jar files that you want
merged in.
Well, I hope that explains it all.
Dave
_______________________________________________
xcode-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/xcode-users
Do not post admin requests to the list. They will be ignored.