|
| 1 | + ----- |
| 2 | +Plexus Applications and Runtimes |
| 3 | + ----- |
| 4 | +Trygve Laugstol |
| 5 | +Emmanuel Venisse |
| 6 | + ----- |
| 7 | + |
| 8 | +Building Plexus Applications and Runtimes |
| 9 | + |
| 10 | + To be able to build Plexus applications and runtimes you'll need: |
| 11 | + |
| 12 | + * The Plexus mojo |
| 13 | + |
| 14 | + * The Plexus application archetype |
| 15 | + |
| 16 | + * The Plexus runtime archetype |
| 17 | + |
| 18 | + <<<TODO: Make a link to the maven site that explains what a archetype is.>>> |
| 19 | + |
| 20 | +Introduction |
| 21 | + |
| 22 | + Some stub directories will be created: |
| 23 | + |
| 24 | + [<<</my-component>>>] - Here we'll make a Plexus component |
| 25 | + |
| 26 | + [<<</my-application>>>] - Here we'll make an application |
| 27 | + |
| 28 | + [<<</my-runtime>>>] - Here we'll make a runtime that will host your |
| 29 | + application. This runtime will contain startup scripts for Unix, Windows and |
| 30 | + OS X and will be completly standalone. |
| 31 | + |
| 32 | +Creating a Simple Plexus Component |
| 33 | + |
| 34 | +* Making the Component Stub |
| 35 | + |
| 36 | ++-----------------------------------------------------------------------------+ |
| 37 | +$ mvn archetype:create \ |
| 38 | + -DarchetypeGroupId=org.codehaus.plexus \ |
| 39 | + -DarchetypeArtifactId=plexus-archetype-component-simple \ |
| 40 | + -DarchetypeVersion=1.0-alpha-1-SNAPSHOT \ |
| 41 | + -DgroupId=mygroup \ |
| 42 | + -DartifactId=my-component \ |
| 43 | + -Dversion=1.0-SNAPSHOT \ |
| 44 | + -Dpackage=my.component |
| 45 | ++-----------------------------------------------------------------------------+ |
| 46 | + |
| 47 | +* Building the Plexus Component |
| 48 | + |
| 49 | + To build the component simply type in <<</my-component>>>: |
| 50 | + |
| 51 | ++-----------------------------------------------------------------------------+ |
| 52 | +$ mvn install |
| 53 | ++-----------------------------------------------------------------------------+ |
| 54 | + |
| 55 | + You should now have a packaged Plexus component in <<<target/my-component-1.0-SNAPSHOT.jar>>> |
| 56 | + |
| 57 | +Creating a Simple Plexus Application |
| 58 | + |
| 59 | +* Making the Application Stub |
| 60 | + |
| 61 | ++-----------------------------------------------------------------------------+ |
| 62 | +$ mvn archetype:create \ |
| 63 | + -DarchetypeGroupId=org.codehaus.plexus \ |
| 64 | + -DarchetypeArtifactId=plexus-archetype-application \ |
| 65 | + -DarchetypeVersion=1.0-alpha-1-SNAPSHOT \ |
| 66 | + -DgroupId=mygroup \ |
| 67 | + -DartifactId=my-application \ |
| 68 | + -Dversion=1.0-SNAPSHOT \ |
| 69 | + -Dpackage=my.app |
| 70 | ++-----------------------------------------------------------------------------+ |
| 71 | + |
| 72 | +* Adding the Plexus Component dependency |
| 73 | + |
| 74 | + You need to add the following dependency in <<</my-application>>> pom: |
| 75 | + |
| 76 | ++-----------------------------------------------------------------------------+ |
| 77 | + <dependency> |
| 78 | + <groupId>mygroup</groupId> |
| 79 | + <artifactId>my-component</artifactId> |
| 80 | + <version>1.0-SNAPSHOT</version> |
| 81 | + </dependency> |
| 82 | ++-----------------------------------------------------------------------------+ |
| 83 | + |
| 84 | + and in <<<src/conf/application.xml>>>, add this so the Plexus component will be |
| 85 | + loaded at startup: |
| 86 | + |
| 87 | ++-----------------------------------------------------------------------------+ |
| 88 | + <load-on-start> |
| 89 | + <component> |
| 90 | + <role>mygroup.HelloWorld</role> |
| 91 | + </component> |
| 92 | + </load-on-start> |
| 93 | ++-----------------------------------------------------------------------------+ |
| 94 | + |
| 95 | +* Building the Plexus Application |
| 96 | + |
| 97 | + To build the application simply type in <<</my-application>>>: |
| 98 | + |
| 99 | ++-----------------------------------------------------------------------------+ |
| 100 | +$ mvn plexus-appserver:assemble-app |
| 101 | ++-----------------------------------------------------------------------------+ |
| 102 | + |
| 103 | + and you should have a application in <<<target/plexus-application>>>. Inside |
| 104 | + the exploded application there will be two directories: <<<conf>>> and |
| 105 | + <<<lib>>>. The <<<conf>>> directory contains the configuration file for your |
| 106 | + application and <<<lib>>> contains all the dependencies the application has. |
| 107 | + |
| 108 | + If you want to do some extra processing on these files or possibly add your |
| 109 | + own files you can have a plugin with a post goal on <<<plexus:app>>> and it |
| 110 | + would be invoked before the application was packaged. |
| 111 | + |
| 112 | + If you now run the <<<plexus-appserver:package-app>>> goal: |
| 113 | + |
| 114 | ++-----------------------------------------------------------------------------+ |
| 115 | +$ mvn plexus-appserver:package-app |
| 116 | ++-----------------------------------------------------------------------------+ |
| 117 | + |
| 118 | + the resulting JAR file will be ready for deployment in a Plexus runtime. Our |
| 119 | + example application JAR will be |
| 120 | + <<<target/my-application-1.0-SNAPSHOT.jar>>>. |
| 121 | + |
| 122 | + you can run the above commands in one: |
| 123 | + |
| 124 | ++-----------------------------------------------------------------------------+ |
| 125 | +$ mvn install |
| 126 | ++-----------------------------------------------------------------------------+ |
| 127 | + |
| 128 | +Creating the Runtime |
| 129 | + |
| 130 | +* Making the Runtime Stub |
| 131 | + |
| 132 | + Creating the stub runtime is as easy as creating the application: |
| 133 | + |
| 134 | ++-----------------------------------------------------------------------------+ |
| 135 | +$ mvn archetype:create \ |
| 136 | + -DarchetypeGroupId=org.codehaus.plexus \ |
| 137 | + -DarchetypeArtifactId=plexus-archetype-runtime \ |
| 138 | + -DarchetypeVersion=1.0-alpha-1-SNAPSHOT \ |
| 139 | + -DgroupId=mygroup \ |
| 140 | + -DartifactId=my-runtime \ |
| 141 | + -Dversion=1.0-SNAPSHOT \ |
| 142 | + -Dpackage=my.runtime |
| 143 | ++-----------------------------------------------------------------------------+ |
| 144 | + |
| 145 | +* Building the Runtime |
| 146 | + |
| 147 | ++-----------------------------------------------------------------------------+ |
| 148 | +$ mvn package |
| 149 | ++-----------------------------------------------------------------------------+ |
| 150 | + |
| 151 | + You should now have a usable runtime in <<<target/plexus-runtime>>> and a |
| 152 | + packaged runtime in <<<target/my-runtime-1.0-SNAPSHOT.jar>>>. Now lets copy |
| 153 | + over the application: |
| 154 | + |
| 155 | ++-----------------------------------------------------------------------------+ |
| 156 | +$ cp ../my-application/target/my-application-1.0-SNAPSHOT.jar \ |
| 157 | + target/plexus-app-runtime/apps |
| 158 | ++-----------------------------------------------------------------------------+ |
| 159 | + |
| 160 | + You can also add a dependency on my-application in the my-runtime pom, so it won't |
| 161 | + be necessary to copy the application manually in the runtime. |
| 162 | + |
| 163 | ++-----------------------------------------------------------------------------+ |
| 164 | + <dependency> |
| 165 | + <groupId>mygroup</groupId> |
| 166 | + <artifactId>my-application</artifactId> |
| 167 | + <version>1.0-SNAPSHOT</version> |
| 168 | + <type>plexus-application</type> |
| 169 | + </dependency> |
| 170 | ++-----------------------------------------------------------------------------+ |
| 171 | + |
| 172 | + Now you have a working Plexus runtime with your application installed. To |
| 173 | + start it run: |
| 174 | + |
| 175 | ++-----------------------------------------------------------------------------+ |
| 176 | +$ sh target/plexus-app-runtime/bin/plexus.sh |
| 177 | ++-----------------------------------------------------------------------------+ |
| 178 | + |
| 179 | + Hopefully you should now have a runtime running with. The message "Starting Hello Component." |
| 180 | + sended by <<<my-component>>> at startup must appears in logs. |
| 181 | + |
| 182 | +Getting fancy: Adding a Shared Servlet Container |
| 183 | + |
| 184 | + Plexus runtimes can have a set of services thats shared between the applications. |
| 185 | + One very useful service is a servlet container. This enables several isolated applications |
| 186 | + to share the same Jetty instance without the need for complicated Apache HTTPD proxy |
| 187 | + setups. The servlet container service will all the web in a configured |
| 188 | + directory. The application contains a commented out configuration section for |
| 189 | + the servlet container which you must uncomment so the service would be |
| 190 | + enabled. |
| 191 | + |
| 192 | + <<<NOTE: This example assumes that you have the runtime that was created in the last section.>>> |
| 193 | + |
| 194 | + First add the service dependency into the runtime: |
| 195 | + |
| 196 | ++-----------------------------------------------------------------------------+ |
| 197 | + <dependency> |
| 198 | + <groupId>org.codehaus.plexus</groupId> |
| 199 | + <artifactId>plexus-appserver-service-jetty</artifactId> |
| 200 | + <version>2.0-alpha-1</version> |
| 201 | + <type>plexus-service</type> |
| 202 | + </dependency> |
| 203 | ++-----------------------------------------------------------------------------+ |
| 204 | + |
| 205 | + Now we need to add a web application to the application. As a simple web |
| 206 | + application we're using the Jetty JavaDocs. Add this in <<<my-application>>> pom: |
| 207 | + |
| 208 | ++-----------------------------------------------------------------------------+ |
| 209 | + <dependency> |
| 210 | + <groupId>jetty</groupId> |
| 211 | + <artifactId>javadoc</artifactId> |
| 212 | + <version>4.2.23RC0</version> |
| 213 | + <type>war</type> |
| 214 | + </dependency> |
| 215 | ++-----------------------------------------------------------------------------+ |
| 216 | + |
| 217 | + Now we need to configure the servlet container service so it knows where to |
| 218 | + find the web applications. In <<<src/conf/application.xml>>> uncomment the servlet |
| 219 | + container section. Now bundle the application again: |
| 220 | + |
| 221 | ++-----------------------------------------------------------------------------+ |
| 222 | +$ mvn install |
| 223 | ++-----------------------------------------------------------------------------+ |
| 224 | + |
| 225 | + We suppose there you added <<<my-application>>> dependency in <<<my-runtime>>> pom. |
| 226 | + Execute this commands from <<</my-runtime>>> |
| 227 | + |
| 228 | ++-----------------------------------------------------------------------------+ |
| 229 | +$ mvn package |
| 230 | ++-----------------------------------------------------------------------------+ |
| 231 | + |
| 232 | + Now when the application server is started again it should |
| 233 | + |
| 234 | + * Deploy the servlet container. |
| 235 | + |
| 236 | + * Boot Jetty. |
| 237 | + |
| 238 | + * Deploy the application. |
| 239 | + |
| 240 | + * The servlet container will detect that a new application was deployed and deploy the JavaDoc WAR. |
| 241 | + |
| 242 | + So lets start it: |
| 243 | + |
| 244 | ++-----------------------------------------------------------------------------+ |
| 245 | +$ sh target/plexus-app-runtime/bin/plexus.sh |
| 246 | ++-----------------------------------------------------------------------------+ |
| 247 | + |
| 248 | + And open your browser to http://localhost:8080/ |
0 commit comments