Note: OpenShift is free "platform as a service", where you can have hosted any Java EE app, but also PHP, Ruby and Python apps.
Creating a Java EE 6 app with Wicket framework for view layer to be deployed to OpenShift is quite straightforward and easy.
It's done in few steps:
1) Create an account on OpenShift.
You'll need an SSH key. Generate one if you don't have yet.
Then, create a new application of type JBoss AS 7.
Follow the instructions given by OpenShift up to cloning the newly created git repository.
You should end up with that repository cloned locally.
Also add a MySQL cartridge.
Now we are going to replace the placeholder app with our wicket app. A good start is to take the JBoss AS Wicket + JPA quickstart..
2) Next to that new repository, clone the JBoss AS Quickstart project.
git clone git://github.com/jbossas/quickstart.git cd quickstart git checkout origin/master ## Just to be sure .-)
3) Examine the wicket-war Maven project.
From wicket-war's pom.xml, copy the following bits to your new application's pom.xml:
Properties...
<!-- Define the version of JBoss' Java EE 6 APIs we want to import. --> <jboss.spec.version>3.0.0.Final</jboss.spec.version> <wicket.version>1.5.20</wicket.version> <wicket.cdi.version>1.2</wicket.cdi.version>
<build> configures maven to pick resources from src/main/java, defines the JBoss AS plugin (for normal deployment during development) and JDK version.
<build> ... </build>
Dependencies definitions...
<dependencyManagement> ... </dependencyManagement> <dependencies> ... </dependencies>
Don't delete the openshift profile. That's used for building the project in OpenShift.
4) Merge both web.xml's.
5) Datasource
Check .openshift/config/standalone.xml . OpenShift has prepared a datasource configured through system properties - see the user guide.
Let's assume you've chosen MySQL, so you'll use java:jboss/datasources/MysqlDS in your persistence.xml.
<persistence-unit name="primary"> <!-- OpenShift gives us a datasource props through system properties - see .openshift/config/standalone.xml . --> <jta-data-source>java:jboss/datasources/MysqlDS</jta-data-source> <properties> <property name="hibernate.show_sql" value="false" /> </properties> </persistence-unit>
6) Copy the rest of the web app.
Copy the contents of src/ from wicket-web to your new app.
Again, keep the old stuff - the health.jsp. You might want to delete the snoop.jsp when your app goes "Final".
You'll probably also want to do some branding - rename groupId and artifactId in pom.xml, rename the Java packages, etc.
7) Commit and push the code to the remote repo.
This will make openshift to stop the server, compile your app, start the server and deploy the app..
git commit -a -m "Wicket app based on JBoss AS Wicket quickstart." git push origin master
You should end up with output like this:
remote: [INFO] ------------------------------------------------------------------------ remote: [INFO] BUILD SUCCESS remote: [INFO] ------------------------------------------------------------------------ remote: [INFO] Total time: 23.382s remote: [INFO] Finished at: Mon Apr 09 22:07:57 EDT 2012 remote: [INFO] Final Memory: 6M/109M remote: [INFO] ------------------------------------------------------------------------ remote: Running .openshift/action_hooks/build remote: Emptying tmp dir: /var/lib/stickshift/e21eceb8bf7b4a779ffde23afa36b2b2/test/jbossas-7/standalone/tmp/auth remote: Emptying tmp dir: /var/lib/stickshift/e21eceb8bf7b4a779ffde23afa36b2b2/test/jbossas-7/standalone/tmp/vfs remote: Emptying tmp dir: /var/lib/stickshift/e21eceb8bf7b4a779ffde23afa36b2b2/test/jbossas-7/standalone/tmp/work remote: Running .openshift/action_hooks/deploy remote: Starting application... remote: MySQL already running remote: Done remote: Running .openshift/action_hooks/post_deploy To ssh://e21eceb8bf7b4a779ffde23afa36b2b2@test-ondra.rhcloud.com/~/git/test.git/ a793266..40025e4 master -> master
If everything went ok, you should see your brand new Wicket app running on a free JBoss AS hosting! Congrats
Here's the result of the previous steps: http://test-ondra.rhcloud.com/
Known issues
- Due to how current Wicket 1.5.x serialization works, there's an issue when reading old page objects (i.e. browsing in history): https://issues.jboss.org/browse/AS7-4554
- This has a simple fix - add this to META-INF/MANIFEST.MF :
Dependencies: org.jboss.msc
- Wicket 6.0.0 is not integrated with Weld CDI because the Maven central repo doesn't contain necessary artifacts. https://issues.jboss.org/browse/SEAMWICKET-50
Tips
- You may want to use JBoss Serialization for pages serialization - it's faster and can deal with non-serializable classes.
- You may want to use Infinispan / JBoss Enterprise Data Grid as PageStore - it offers unmatched reliability and scalability.
Comments