Skip to main content

Maven2的牛刀小试

想把CyclopsGroup.com上所有的项目里的Maven升级到Maven2已经很久了,一直有很多顾虑。比如怎么和现有的AntHill集成, 过去已经发布的包包该怎么办。为了不影响大局,在新的arapaho这个独立,简单项目上,我决定完全抛弃Maven1。 安装maven2很简单,下载maven-2.0.1的包,解压在某处。把bin/mvn在/usr/local/bin下做一个symbolic link就行了。

第一件要做的事儿是吧CyclopsGroup.com网站搬过来。按照其他maven2里项目的模样,我创建了一个名 叫com.cyclopsgroup.arapaho的项目,并在下面创建arapaho-main-site子项目。这个arapaho-main- site是将来存放网站内容的地方。按照maven网站上创建站点的文档, 我只是简单的把xdoc目录考到src/site/目录下,创建site.xml文件,执行mvn site。静态页面很顺利的生成到了target/site下。

现在的问题是我需要把一段googleanalytics的javascript放到每页的头上。文档上没有指出该怎么做但是从代码上看,在site.xml文件里应该可以写<head>标记。


<project>
<bannerLeft>...
<body>...
<head>
<script src="http://www.google-analytics.com/urchin.js"...
...


很遗憾,mvn site后改动没有任何效果。这是因为当前的maven是2.0.1release,很多包都不是最新的。所以需要下载最近的maven。
svn co http://svn.apache.org/repos/asf/maven/components/trunk, 进入trunk执行./bootstrap.sh, 在maven-core/target下产生最新的maven-2.1-SNAPSHOT-bin。解压到另一个目录,在/usr/local/bin里 重建mvn连接。

再次mvn site还没效果,手工安装最新的插件试一试。 svn co http://svn.apache.org/repos/asf/maven/plugins/trunk, 进入拿到的trunk执行mvn package install。 报错说需要的maven-2.0.2-SNAPSHOT不存在。

原来刚刚做的新的maven是 maven-2.1-SNAPSHOT, 这里插件需要的是2.0.2-SNAPSHOT。 在trunk上最新的maven已经抛开了别的插件走的太远了。果然,在maven/components/branchs里有个maven-2.0.x 分支。把这个分支搞下来:svn co http://svn.apache.org/repos/asf/maven/components/branches/maven-2.0.x 再用./bootstrap.sh做一个maven包,这回是maven-2.0.2-SNAPSHOT-bin。

解压新的包,重建/usr/local/bin/mvn, 再在arapaho-main-site里做mvn site, 得到一些velocity错误,大概是说244行的$item.toUnescapedString()不认识。打开site的velocity模板, 这行偏偏就是我要的东西。


#if ( $decoration.body.head )
#foreach( $item in $decoration.body.head.getChildren() )
#if ( $item.name == "script" )
$item.toUnescapedString()
#else
$item.toString()
#end
#end
#end


$decoration 是何许人士?这些代码已经跑到了maven的doxia子项目里面,大概还是包版本的问题。svn拿到doxia项目,mvn package install, 可问题还没有解决。难道maven-site-plugin一定要求用户用它自己的模板,我想要个简单的都不行吗?不会的。打开这段程序, 从execute方法里可以看出,site插件不仅像maven1一样允许你指定一个自己的velocity template, 还可以在site.xml里指定一个site skin包。

在arapaho大项目里建arapaho-skin-default子项目,内容很简单:

src/main/resource
+ images/some iamges
+ css/site.css
+ META-INF/maven/site.vm(modified)

site.vm里加进去了我想要的javascript,并对页面的格式做了很多修改。给arapaho-skin-default做mvn package install, 修改arapaho-main-site的site.xml

<project>
<skin>
<groupId>com.cyclopsgroup.arapaho</groupId>
<artifactId>arapaho-skin-default</artifactId>
<version>1.0-SNAPSHOT</version>
</skin>
<bannerLeft>...
...

原来的head标签就不用了。

再mvn site, 问题解决。这个arapaho-skin-default将来也可以在别的项目上重用。

Comments

Popular posts from this blog

Spring, Angular and other reasons I like and hate Bazel at the same time

For several weeks I've been trying to put together an Angular application served Java Spring MVC web server in Bazel. I've seen the Java, Angular combination works well in Google, and given the popularity of Java, I want get it to work with open source. How hard can it be to run arguably the best JS framework on a server in probably the most popular server-side language with  the mono-repo of planet-scale ? The rest of this post walks through the headaches and nightmares I had to get things to work but if you are just here to look for a working example, github/jiaqi/angular-on-java is all you need. https://github.com/jiaqi/angular-on-java Java web application with Appengine rule Surprisingly there isn't an official way of building Java web application in Bazel, the closest thing is the Appengine rule  and Spring MVC seems to work well with it. 3 Java classes, a JSP and an appengine.xml was all I need. At this point, the server starts well but I got "No

Wreck-it Ralph is from Chicago?

Hotel Felix in Chicago   The building of Fix-it Felix Jr.  

Project Euler problem 220 - Heighway Dragon

This document goes through a Java solution for Project Euler problem 220 . If you want to achieve the pleasure of solving the unfamiliarity and you don't have a solution yet, PLEASE STOP READING UNTIL YOU FIND A SOLUTION. Problem 220 is to tell the coordinate after a given large number of steps in a Dragon Curve . The first thing came to my mind, is to DFS traverse a 50 level tree by 10^12 steps, during which it keeps track of a direction and a coordinate. Roughly estimate, this solution takes a 50 level recursion, which isn't horrible, and 10^12 switch/case calls. Written by a lazy and irresponsible Java engineer, this solution vaguely looks like: Traveler traveler = new Traveler(new Coordinate(0, 0), Direction.UP); void main() { try { traverse("Fa", 0); } catch (TerminationSignal signal) { print signal; } } void traverse(String plan, int level) { foreach(char c:plan) { switch(c) { case 'F': traveler.stepForward(); break; ca