It took me several weekends to get maven working with my simple Web application.
My first approach was to use Apache Maven Eclipse Plugin, and add some tricks to work around its limitations. See my comments in Spring Forum dm Server Tooling and Maven: is it possible?
The issue is Maven Eclipse Plugin has not considered dm Server facet settings yet, so you have to manually add WTP project facet setting for dm Server in .settings\org.eclipse.wst.common.project.facet.core.xml file. There maybe some other ways to work around, but not neat.
Then I was thinking about extending its Mojo class org.apache.maven.plugin.eclipse.EclipsePlugin, and by adding additional project natures, build commands, etc. and we were done, just like M2EclipseMojo does. Although hadn't programmed Maven Plugin before, by reading tutorial and source code of Maven Eclipse Plugin, I thought it should be easy.
Setting up a plugin project is easy by following the Plugin Developer's document. Then I spent a whole morning struggling with NPE. First subclassed EclipsePlugin in my plugin project as S2DMEclipseMojo, and in the mojo, added dm Server related config for eclipse, similar to M2EclipseMojo. Theoretically it should work. But the project injected to the plugin was always null.
Tried all kinds of ways to figure out what's wrong, but no clue. Then started to search around in the Internet. Suddenly found this JIRA issue of Maven MPLUGIN-56 Inter-plugin Mojo inheritance. Hmm, Plexus should use JDK 5 annotation instead of javadoc annotation.
Anyway, the problem was found, so the dumb solution was to create a mojo class by copying code from EclipsePlugin and its superclass. After many tests and reviews, I found quite a lot of code is dealing with dependencies. Since we already use dm Server Tool to handle bundle dependency through MANIFEST.MF file, and we can use M2Eclipse plugin in Eclipse to handle unit test related dependencies like junit, easy mock, why not remove all those messy code? So a very simple mojo class was done and tested, seems it meets our needs. See the source code for S2DMEclipseMojo
This is my first Maven Plugin Project, very exciting. Then spent another weekend to get it released as 0.0.1, add documentation, publish to Google Code. It is very nice that we can use Google Code SVN service to publish our Web site and maven repository. See Open Toast Maven Plugin for SpringSource dm Server v0.0.1. The trick is you have to add svn property for all html files as "text/html" mime type. Maybe there is a easy way to do that, I don't know.
To use this plugin is very easy, simply by adding plugin repository in your project pom.xml, like:
opentoast.maven.s2dm.plugin http://opentoastproject.googlecode.com/svn/mavenrepo
and then in your project root, type
mvn org.opentoast:maven-s2dm-plugin:0.0.1:eclipse
It will add Eclipse settings for the project, so you can import into Eclipse. Suppose you already set up your Eclipse with M2Eclipse and dm Server Tool plugins. You may have to run "Spring Tools - Refresh Bundle Dependencies" to get rid of compiler errors.
To use dm Server Tool with M2Eclipse, I apply another trick learned from Spring forum, that put all bundle dependencies to a profile, so M2Eclipse Plugin cannot find them.
The complete pom for my simple Web application is like this:
4.0.0 org.simple org.simple.web jar Simple Web Bundle 0.0.1-SNAPSHOT 3.2.2 2.5.6.A 1.1.2.A 1.0.1 1.5.0 2.5.0 2.1.0 1.1.2 4.5.0 2.3.0 bundle org.springframework org.springframework.beans ${spring.version} provided org.springframework org.springframework.core ${spring.version} provided org.springframework org.springframework.context ${spring.version} provided org.springframework org.springframework.context.support ${spring.version} provided org.springframework org.springframework.web ${spring.version} provided org.springframework org.springframework.web.servlet ${spring.version} provided javax.servlet com.springsource.javax.servlet ${servlet.version} provided javax.servlet com.springsource.javax.servlet.jsp ${jsp.version} provided org.apache.taglibs com.springsource.org.apache.taglibs.standard ${jstl.version} provided org.easymock com.springsource.org.easymock ${easymock.version} test org.junit com.springsource.org.junit ${junit.version} test org.springframework org.springframework.test ${spring.version} test org.apache.maven.plugins maven-compiler-plugin 1.6 org.apache.maven.plugins maven-jar-plugin src/main/resources/META-INF/MANIFEST.MF opentoast.maven.s2dm.plugin http://opentoastproject.googlecode.com/svn/mavenrepo com.springsource.repository.bundles.release SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases http://repository.springsource.com/maven/bundles/release com.springsource.repository.bundles.external SpringSource Enterprise Bundle Repository - External Bundle Releases http://repository.springsource.com/maven/bundles/external
See my post Simple Web Application with SpringSource dm Server for other details.
Next step is to focus on Open Toast Project again, and get the whole system running. One goal of open toast project is to set up infrastructure so I can work on business later or easily create new projects. However, it is too long to get infrastructure done, especially when using cutting edge technologies. But isn't it fun?
No comments:
Post a Comment