Wiki source code of Create a WebObjects Framework

Version 45.1 by Pascal Robert on 2007/12/15 18:15

Hide last authors
Pascal Robert 45.1 1 {{toc}}{{/toc}}
Pascal Robert 15.1 2
Pascal Robert 45.1 3 = Introduction =
4
5 So, you have built the mother of all WebObjects apps in XCode or Eclipse with everything in the default package (or not ;-) ). The time has come where you want a make a new WebObjects application that re-uses some of the functionality you have already created in bigApp.woa.
Kieran Kelleher 43.1 6 This article explains how to create a framework in Eclipse that can be used with your WebObjects projects. The resulting framework can be used in WOLips or XCode projects. In this example a framework is created that consists of class(es) that were in the default package of a WebObjects application and the 3rd party jar dependencies that were originally in /Library/WebObjects/Extensions. The resulting framework bundle will encompass the 3rd party jar and the custom java classes that are moved from the original WO project.
7 Disclaimer: I am still relatively new to Eclipse, so if you see a smarter way to do this, then feel free to edit this wiki page
Pascal Robert 15.1 8 Also, at the time of writing this article I was using Eclipse 3.2.1 with WOLips build #3769.
9
Pascal Robert 45.1 10 = How To... =
Pascal Robert 15.1 11
Pascal Robert 45.1 12 == Adjust Your Filters ==
Kieran Kelleher 33.1 13
Kieran Kelleher 35.1 14 Before you start, edit your Package Explorer filters so that we can really "see" the files in our project, especially so we can check if our project was created correctly by the wizard later on. To do this simply select Filters from the Package Explorer contextual menu as shown below:
Kieran Kelleher 33.1 15
Pascal Robert 45.1 16 {{info}}
Kieran Kelleher 33.1 17
Pascal Robert 45.1 18 !packageExplorer-filters.jpg!
Pascal Robert 15.1 19
Pascal Robert 45.1 20 {{/info}}
21
22 ... and then deselect everything except the ones shown here. This of course is a user preference, but at least your screen will match my initial project picture shown here if you do as I tell you
23
24 {{info}}
25
26 !javaElementFilters.jpg!
27
28 {{/info}}
29
30 == Create the Framework project in your Eclipse workspace. ==
31
Kieran Kelleher 25.1 32 Right-click in Package Explorer view of the WOLips perspective and select New->Other.
Pascal Robert 15.1 33
Pascal Robert 45.1 34 {{info}}
35
36 !new-project-other.jpg!
37
38 {{/info}}
39
Pascal Robert 15.1 40 Next type WO in the filter field and select WOnderFramework from the list and click Next.
41
Pascal Robert 45.1 42 {{info}}
43
44 !new-WOnderFramework.jpg!
45
46 {{/info}}
47
Pascal Robert 15.1 48 Next enter a project name and click Finish
49
Pascal Robert 45.1 50 {{info}}
51
52 !WOnderFramework-projectname.jpg!
53
54 {{/info}}
55
Kieran Kelleher 43.1 56 **WOLips Bug: If your new framework project DOES NOT look like the one in the picture below, then you have come across a known elusive WOLips bug that the team is trying to solve. In the case that your project does not look like this, the fix is to select the project and then select the Project->Close in the main menu bar. Afterward select Project->Open and then expand your project and it should be OK.**
Kieran Kelleher 33.1 57
Pascal Robert 45.1 58 {{info}}
59
60 !example-framework.jpg!
61
62 {{/info}}
63
Kieran Kelleher 43.1 64 **Another Minor Bug: In the latest build I was using, the default framework project does not contain a folder named 'Components' which it needs to have a successful build later. So just create a new folder in the project named Components. Right-click the project > New > Folder**
65
Pascal Robert 45.1 66 {{info}}
Kieran Kelleher 33.1 67
Pascal Robert 45.1 68 !newComponentsFolder.jpg!
Kieran Kelleher 33.1 69
Pascal Robert 45.1 70 {{/info}}
Kieran Kelleher 35.1 71
Pascal Robert 45.1 72 == Bundling 3rd Party Jars in your Framework ==
73
74 Next add any 3rd party jar files to your project that you want bundled with this framework. This is probably the "best practice" way to make 3rd party jars available to your WebObjects apps rather than stuffing them into /Library/WebObjects/Extensions, or even worse, putting them in /Library/Java/Extensions, which can lead to deployment hassles later.
75
Kieran Kelleher 33.1 76 To do this simply locate the jar in the Finder and drag and drop it on the Libraries folder in your project as shown here:
77
Pascal Robert 45.1 78 {{info}}
Kieran Kelleher 33.1 79
Pascal Robert 45.1 80 !dragJarToLibraries.jpg!
Kieran Kelleher 35.1 81
Pascal Robert 45.1 82 {{/info}}
Kieran Kelleher 33.1 83
Pascal Robert 45.1 84 Next simply right-click on the jar file itself and select Build Path > Add to Build Path.
Kieran Kelleher 33.1 85
Pascal Robert 45.1 86 {{info}}
Kieran Kelleher 33.1 87
Pascal Robert 45.1 88 !Picture 7.jpg!
89
90 {{/info}}
91
92 IMPORTANT:
93
94 * Next right-click on the project and select Build Path > Configure Build Path...
95 * Then to to the Order and Export tab and turn ON the checkbox next to the jar that you just added to the build path. By doing this, the jars in the framework are automatically available to any WebObjects apps/frameworks that depend on this framework in your workspace.
96
97 Adding dependencies on other frameworks can be done at this stage if you wish. The procedure is the same as for adding framework dependencies to a WOApplication which also has a tutorial. Keep in mind that the WOnder Framework wizard adds default framework links which you can adjust and turn off easily (right-click WOFrameworks icon and select Configure)
98
99 == Create a package (or packages) for your reusable classes. ==
100
Kieran Kelleher 35.1 101 Right-click on the Sources folder and select New > Package as shown here:
Kieran Kelleher 33.1 102
Pascal Robert 45.1 103 {{info}}
104
105 !Sources-new-package.jpg!
106
107 {{/info}}
108
Kieran Kelleher 33.1 109 Enter a name for the package and Eclipse automatically creates the appropriate folder structure in the file system:
110
Pascal Robert 45.1 111 {{info}}
Kieran Kelleher 33.1 112
Pascal Robert 45.1 113 !NewJavaPackage.jpg!
Kieran Kelleher 35.1 114
Pascal Robert 45.1 115 {{/info}}
Kieran Kelleher 35.1 116
Pascal Robert 45.1 117 == Add classes to your package. You can drag java files from the file system or XCode to the package: ==
118
119 {{info}}
120
121 !dragClassToPackage.jpg!
122
123 {{/info}}
124
125 == Cleanup Time ==
126
Kieran Kelleher 41.1 127 Eclipse will check and compile your classes and sprinkle red x's and yellow exclamations on the areas needing your attention. (Isn't Eclipse just great ... intelligent assistance, refactoring, etc.) Anyway go ahead and fix/refactor to fix code problems and resolve dependencies. There is nothing like trying to package a large "default package" app to show you where you have opportunities to clean up dependencies or to show you dependencies you did not realize you had
Kieran Kelleher 35.1 128
Pascal Robert 45.1 129 {{info}}
Kieran Kelleher 35.1 130
Pascal Robert 45.1 131 !codeCleanUp.jpg!
132
133 {{/info}}
134
135 == Install The Framework ==
136
Kieran Kelleher 35.1 137 Building and/or installing is the same as for WOApplications in Eclipse
Pascal Robert 45.1 138
139 {{info}}
140
141 !installFramework.jpg!
142
143 {{/info}}