Re: Common library, how to
Re: Common library, how to
- Subject: Re: Common library, how to
- From: "Jerry W. Walker" <email@hidden>
- Date: Mon, 23 Jan 2006 08:16:15 -0500
Hi, Xavier,
On Jan 23, 2006, at 6:08 AM, Dev WO wrote:
Hi list,
this is really a beginner question...most probably because I'm
still a beginner;)
I'd like to share some code between different applications, so I
was thinking about creating "something" that would holds my shared
code.
So here's a few question if someone can point me to the correct
resource or give me the answer:
-Which type of project should I choose: a "WebObject Framework" or
an "Ant-based Java Library"? I'm pretty sure there's different goal
using one or the other, but I don't actually get all of them
The generally accepted way to do this in WO is to create a WO
framework. I haven't created Ant-based Java Libraries, so I can't
answer your question about specific differences in goals. Although
there's a technical difference in the definitions between "framework"
and "library", those differences have so blurred over time that there
is little practical difference today in many cases.
Apple's definition of a Framework is more specific and more technical
than I wish to expose here, since you're starting from a Java
perspective.
My understanding of the original (industry) definitions were:
library - a collection of subroutines and functions that are meant
to be called to perform services for your application (e.g. math
library)
framework - a working application that provides the common pieces
of a technology with hooks to include your customized code
The difference between the two was basically that in the use of a
library, your application was always in control and it requested
services from the library when it needed them; in a framework, the
framework was in control (and could potentially be built and run
without any customization); you extended and customized the framework
by subclassing specific classes of the framework or by adding
functions or classes that it would use.
You'll notice that this definition of framework works appropriately
for the WebObjects framework. When creating a new WO application, you
can build and run it successfully before customizing it in any way.
All it does is vend a blank page, but there's a lot of infrastructure
that goes into that simple act that you don't have to create yourself
for every new project.
Today, I think that a framework differs from a library more from the
standpoint of what can be included. About the only thing you can add
to a library is code (packages, classes, methods). A framework can
include all of that and other resources as well, such as images,
HTML, text files, property lists, audio files, etc. In short, you can
add anything to a framework that you could add to an application.
-Where could I found a beginner "how to" about this?
You could probably find the information in the Xcode Framework
Programming Guide:
http://developer.apple.com/documentation/MacOSX/Conceptual/
BPFrameworks/Concepts/FrameworkBinding.html
But you can also find it below. This is easy to do and will generally
address all your code sharing concerns.
To do this
* create a new project in Xcode
* in the New Project wizard, select WebObjects Framework under the
WebObjects heading and click Next
* select a location and name (let's call it X.framework) for your
framework and click Finish
* add any Frameworks to X.framework that it will need to do its
work (for instance, if you put your EOModels here, you might want to
include the JavaJDBCAdaptor.framework).
* add or create any classes, WOComponents or resources to the
framework that you wish to share
* develop within the framework exactly as you would within an
application, except a framework can't be "executed" for testing.
* when you build the framework, find the package Development/
X.framework within your build directory
* move or copy X.framework to your install location, I use /Local/
Library/Frameworks, some use /Library/Frameworks
* add your installed framework to any of the projects in which you
wish to share the code just like you would add any other framework.
The advantage of using your new framework, of course, is that you can
share code and resources. The disadvantage is that development and
testing of the code in your framework introduces an additional step
(3 below) in your development process :
1) modify the framework code
2) build the framework
3) move the framework to the deployment location
4) restart an application that uses the framework to test
Other than the additional step, you work with a framework in the same
way you work with an application. However, because of the extra step,
I usually start by creating an application that would use the
framework with all of the framework's contents in the application. I
develop and debug the application until the pieces that will go in
the framework have stabilized. Then I create the framework, copy over
the pieces into the framework from the application, delete them from
the application and include the framework in the application. I debug
that combination until I'm confident that the framework is working,
then I add it to the other projects.
Here's what I tried so far, creating an ant-based java library:
I wanted to use some of Apache Commons Lang method, so I imported
"import org.apache.commons.lang.*;"
but when I try to use the method, it doesn't compile saying the
method doesn't exist...But I'm actually using them directly in my
WO application and it works.
So I tried copying the entire method inside my own code to see if
it would work, but it won't compile!
If I add the entire Java file from Commons Lang, it fails compiling
only on my own class, and not on the Apache one...I only copied and
pasted!
I'm not sure why your code won't compile as part of an Ant-based
library. As I said earlier, I haven't tried to create one of these
except to the extent that Xcode does it for me. However, it sounds
like neither your library nor your application is finding the class
containing the method, so the first place I would look is in my Java
ClassPath to be sure it includes the path to that class.
So I may not doing it the correct way:(
Can someone point me to some resources about creating java
libraries (ideally using Xcode;))?
Hopefully this message will have answered your questions. If not, ask
(but please address further questions back to the list to get the
most possible help) or reference the Xcode documentation.
Regards,
Jerry
--
__ Jerry W. Walker,
WebObjects Developer/Instructor for High Performance Industrial
Strength Internet Enabled Systems
email@hidden
203 278-4085 office
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden