Wiki source code of Packaging WO Applications as true WAR with Maven
Version 18.1 by Greg.Brown on 2009/08/02 13:30
Show last authors
| author | version | line-number | content |
|---|---|---|---|
| 1 | If you have used the [[woapplication-archetype]] 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>>^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>>^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 | <plugins> | ||
| 37 | ... | ||
| 38 | <plugin> | ||
| 39 | <artifactId>maven-war-plugin</artifactId> | ||
| 40 | <configuration> | ||
| 41 | <archiveClasses>true</archiveClasses> | ||
| 42 | </configuration> | ||
| 43 | </plugin> | ||
| 44 | ... | ||
| 45 | </plugins> | ||
| 46 | ... | ||
| 47 | </build> | ||
| 48 | |||
| 49 | {{/noformat}} | ||
| 50 | |||
| 51 | == Step 4: Add the required dependencies == | ||
| 52 | |||
| 53 | You must add the following dependency to run the application as a true WAR: | ||
| 54 | |||
| 55 | {{noformat}} | ||
| 56 | |||
| 57 | <dependency> | ||
| 58 | <groupId>com.webobjects</groupId> | ||
| 59 | <artifactId>JavaWOJSPServlet</artifactId> | ||
| 60 | <version>${woversion}</version> | ||
| 61 | </dependency> | ||
| 62 | |||
| 63 | {{/noformat}} | ||
| 64 | |||
| 65 | **NOTE**: If you are using WebObjects 5.2.x or 5.3.x you have to add this additional dependency: | ||
| 66 | |||
| 67 | {{noformat}} | ||
| 68 | |||
| 69 | <dependency> | ||
| 70 | <groupId>com.webobjects</groupId> | ||
| 71 | <artifactId>JavaWOJSPServlet_client</artifactId> | ||
| 72 | <version>${woversion}</version> | ||
| 73 | </dependency> | ||
| 74 | |||
| 75 | {{/noformat}} | ||
| 76 | |||
| 77 | **NOTE**: if your application uses Wonder, please read [[this tutorial>>http://wiki.objectstyle.org/confluence/display/WONDER/Creating+a+wonder+app+to+deploy+as+a+servlet]]. | ||
| 78 | |||
| 79 | == Step 5: Change the packaging type == | ||
| 80 | |||
| 81 | The default [[maven-war-plugin>>http://maven.apache.org/plugins/maven-war-plugin/]] can handle the war packaging correctly. You have to change the packaging of your POM to 'war' in order to use this plug-in: | ||
| 82 | |||
| 83 | {{noformat}} | ||
| 84 | |||
| 85 | <packaging>war</packaging> | ||
| 86 | |||
| 87 | {{/noformat}} | ||
| 88 | |||
| 89 | It's done. | ||
| 90 | |||
| 91 | {{panel title="2009 Bug Warning" borderStyle="dashed" borderColor="#ccc" titleBGColor="#F7D6C1" bgColor="#FFFFCE"}} | ||
| 92 | |||
| 93 | It should be done, but... | ||
| 94 | The 2.0.17 archetype does not add : | ||
| 95 | {noformat} | ||
| 96 | <resource> | ||
| 97 | <targetPath>Resources</targetPath> | ||
| 98 | <directory>${basedir}/src/main/components</directory> | ||
| 99 | </resource> | ||
| 100 | {noformat} | ||
| 101 | to the pom.xml file, so your war will have no components; you should add these lines. | ||
| 102 | |||
| 103 | Also, it does not add a necessary WebObjects 5.3 dependency: | ||
| 104 | {noformat} | ||
| 105 | <dependency> | ||
| 106 | <groupId>${webobjects.groupId}</groupId> | ||
| 107 | <artifactId>JavaWOJSPServlet_client | ||
| 108 | </artifactId> | ||
| 109 | <version>${webobjects.version}</version> | ||
| 110 | </dependency> | ||
| 111 | |||
| 112 | {noformat} | ||
| 113 | So, you may need to add that. | ||
| 114 | |||
| 115 | In addition, the archetype generated Info.plist needs fixing, as does the web.xml in the WEB-INF folder. There are values in these files like $\{project.artifactId\}, but for now, you must manually replace those values with actual values, e.g, MyProject. | ||
| 116 | |||
| 117 | These probably will be fixed in the next release of plugins, but for now, watch this space, as there may be additional | ||
| 118 | bugs posted here. | ||
| 119 | |||
| 120 | |||
| 121 | {{/panel}} | ||
| 122 | |||
| 123 | = Running your application as true WAR = | ||
| 124 | |||
| 125 | You can use the [[maven-jetty-plugin>>http://docs.codehaus.org/display/JETTY/Maven+Jetty+Plugin]] to run and test your application. | ||
| 126 | |||
| 127 | == Step 1: Configure the maven-jetty-plugin == | ||
| 128 | |||
| 129 | Add the following configuration to your POM: | ||
| 130 | |||
| 131 | {{noformat}} | ||
| 132 | |||
| 133 | <build> | ||
| 134 | ... | ||
| 135 | <plugin> | ||
| 136 | <groupId>org.mortbay.jetty</groupId> | ||
| 137 | <artifactId>maven-jetty-plugin</artifactId> | ||
| 138 | </plugin> | ||
| 139 | ... | ||
| 140 | </build> | ||
| 141 | |||
| 142 | {{/noformat}} | ||
| 143 | |||
| 144 | == Step 2: Start the Jetty container with Maven == | ||
| 145 | |||
| 146 | Just execute: | ||
| 147 | |||
| 148 | {{noformat}} | ||
| 149 | |||
| 150 | mvn clean jetty:run-war | ||
| 151 | |||
| 152 | {{/noformat}} | ||
| 153 | |||
| 154 | == Step 3: See the result == | ||
| 155 | |||
| 156 | Open a browser and type the URL for your application like this: [[http://locahost:8080/your-app-name/WebObjects/]] |