Last modified by Ulrich Köster on 2009/08/02 20:26

Show last authors
1 If you have used the [[doc:WOL.Home.WOProject-Maven.woapplication-archetype.WebHome]] to create your project, jump to the step 3.
2
3 You have to follow some instructions to build a true WAR package:
4
5 == Step 1: Create a web.xml file ==
6
7 You need to create a web.xml file. You can download a simple web.xml file [[here>>attach:web.xml]]. Don't forget to change the displayName and the WOMainBundle properties:
8
9 {{noformat}}
10
11 <web-app>
12 ...
13 <display-name>Your Application Name</display-name>
14 ...
15 <context-param>
16 <param-name>WOMainBundle</param-name>
17 <param-value>your-app-name</param-value>
18 </context-param>
19 ...
20 </web-app>
21
22 {{/noformat}}
23
24 == Step 2: Create/generate an Info.plist file ==
25
26 You also need to create or generate a valid Info.plist file into your resources folder. [[Here>>attach:Info.plist]] is a sample Info.plist. You have to change the ${your-app-name} and ${package} occurrences with the respective application name and Application class package.
27
28 == Step 3: Package your classes, resources and webserver resources ==
29
30 The application jar must follow the NSJarBundle format. The NSJarBundle is a package organized in Resources and WebServerResources folders. In addition, the Resources folder must contain a valid Info.plist file. Your application classes, resources and webserver resources must be package as a jar. It is easy to configure Maven to do this:
31
32 {{noformat}}
33
34 <build>
35 ...
36 <resources>
37 ...
38 <resource>
39 <targetPath>Resources</targetPath>
40 <directory>${basedir}/src/main/resources</directory>
41 </resource>
42 <resource>
43 <targetPath>Resources</targetPath>
44 <directory>${basedir}/src/main/components</directory>
45 </resource
46 <resource>
47 <targetPath>WebServerResources</targetPath>
48 <directory>${basedir}/src/main/webserver-resources</directory>
49 </resource>
50 ...
51 </resources>
52 ...
53 <plugins>
54 ...
55 <plugin>
56 <artifactId>maven-war-plugin</artifactId>
57 <configuration>
58 <archiveClasses>true</archiveClasses>
59 </configuration>
60 </plugin>
61 ...
62 </plugins>
63 ...
64 </build>
65
66 {{/noformat}}
67
68 == Step 4: Add the required dependencies ==
69
70 You must add the following dependency to run the application as a true WAR:
71
72 {{noformat}}
73
74 <dependency>
75 <groupId>com.webobjects</groupId>
76 <artifactId>JavaWOJSPServlet</artifactId>
77 <version>${woversion}</version>
78 </dependency>
79
80 {{/noformat}}
81
82 **NOTE**: If you are using WebObjects 5.2.x or 5.3.x you have to add this additional dependency:
83
84 {{noformat}}
85
86 <dependency>
87 <groupId>com.webobjects</groupId>
88 <artifactId>JavaWOJSPServlet_client</artifactId>
89 <version>${woversion}</version>
90 </dependency>
91
92 {{/noformat}}
93
94 **NOTE**: If your application uses Wonder you must add the ERXServlet dependency:
95
96 {{noformat}}
97
98 <dependency>
99 <groupId>wonder.core</groupId>
100 <artifactId>ERServlet</artifactId>
101 <version>1.0</version>
102 </dependency>
103
104 {{/noformat}}
105
106 Read this [[tutorial>>url:http://wiki.objectstyle.org/confluence/display/WONDER/Creating+a+wonder+app+to+deploy+as+a+servlet||shape="rect"]] to find how to configure the ERXServletAdaptor in your application.
107
108 == Step 5: Change the packaging type ==
109
110 The default [[maven-war-plugin>>url:http://maven.apache.org/plugins/maven-war-plugin/||shape="rect"]] can handle the war packaging correctly. You have to change the packaging of your POM to 'war' in order to use this plug-in:
111
112 {{noformat}}
113
114 <packaging>war</packaging>
115
116 {{/noformat}}
117
118 It's done.
119
120 == Step 6: Filtering variables with Maven (OPTIONAL) ==
121
122 Maven supports variable substitution during build time. It is called resource filtering. You can find more information about resource filtering [[here>>url:http://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html||shape="rect"]] and [[here>>url:http://www.sonatype.com/books/maven-book/reference/resource-filtering-sect-description.html||shape="rect"]].
123
124 If you are using variables in your resource files (i.e. the Info.plist), you have to configure Maven to filter the Resources folder like this:
125
126 {{noformat}}
127
128 <build>
129 ...
130 <resources>
131 ...
132 <resource>
133 <targetPath>Resources</targetPath>
134 <directory>${basedir}/src/main/resources</directory>
135 <filtering>true</filtering>
136 </resource>
137 ...
138 </resources>
139 ...
140 </build>
141
142 {{/noformat}}
143
144 If you are using variables in the web.xml file, you have to configure Maven to filter deployment descriptors like this:
145
146 {{noformat}}
147
148 <build>
149 ...
150 <plugins>
151 ...
152 <plugin>
153 <artifactId>maven-war-plugin</artifactId>
154 <configuration>
155 ...
156 <filteringDeploymentDescriptors>true</filteringDeploymentDescriptors>
157 </configuration>
158 </plugin>
159 ...
160 </plugins>
161 ...
162 </build>
163
164 {{/noformat}}
165
166 = Running your application as true WAR =
167
168 You can use the [[maven-jetty-plugin>>url:http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin||shape="rect"]] to run and test your application.
169
170 == Step 1: Configure the maven-jetty-plugin ==
171
172 Add the following configuration to your POM:
173
174 {{noformat}}
175
176 <build>
177 ...
178 <plugin>
179 <groupId>org.mortbay.jetty</groupId>
180 <artifactId>maven-jetty-plugin</artifactId>
181 </plugin>
182 ...
183 </build>
184
185 {{/noformat}}
186
187 == Step 2: Start the Jetty container with Maven ==
188
189 Just execute:
190
191 {{noformat}}
192
193 mvn clean jetty:run-war
194
195 {{/noformat}}
196
197 == Step 3: See the result ==
198
199 Open a browser and type the URL for your application like this: [[http:~~/~~/locahost:8080/your-app-name/WebObjects/>>url:http://locahost:8080/your-app-name/WebObjects/||shape="rect"]]