[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: using java .class files in project
>Hi, in my project I'm trying to use pre-compiled java .class files which
>are all stored in a folder (which also contains other class folders).
>This folder structure mimics the java package definition.
>
>How do I include these files in a projectBuilder project?
These instructions are for adding a .jar (Java ARchive), but should work for .class files also.
1) In Makefile.preamble, search for the following two variables, and set them as follows:
JAVA_IS_SERVER_SIDE = YES and
OTHER_CLASSPATH = $(shell pwd)/CommonJava.subproj/Java/MyClasses.jar
2) In your project directory, make a new subdirectory CommonJava.subproj/Java (CommonJava.subproj should already exist).
3) Copy your .jar file into the directory you created in step 2.
4) In Project Builder, highlight the Subprojects --> CommonJava, and drag the Java directory (step 2) from the Windows file viewer into the Resources suitcase.
5) Back at the top level of your project, edit Supporting Files --> CustomInfo.plist, which should look something like this. Note, this must be an absolute path. Relative paths will not work, due to a "feature" of the Java VM class loader.
{
// ** Add your class paths (blah blah blah)
NSJavaUserPath = (C:/MyJunk/JarTest/JarTest.woa/Resources/Java/imajar.jar);
}
That's it! If you follow these steps, you won't need to explicitly import your classes.
Note: You need to set OTHER_CLASSPATH in your Makefile.preamble to satisfy the Java compiler. But you also need NSJavaUserPath to satisfy the Java runtime, because the classes in the JAR file aren't statically linked into your program. You can also set your CLASSPATH environment variable instead of setting NSJavaUserPath, but NSJavaUserPath is usually more convenient for deployment purposes.
--
Cliff Tuel -- ctuel@apple.com
Enterprise Technical Support / Apple Computer, Inc.