Saturday, November 27, 2010

用maven来运行一个main方法或者启动Server

在maven项目的pom.xml文件的plugins中加入"exec-maven-plugin"这个插件,这个在运行"mvn package"时,会在当前的mvn进程中直接执行指定的class文件的main方法,也可以配置其他的参数,让此main在另一个java进程中启动。如果其中将phase的内容改为"test",就会在运行"mvn test"时执行main方法,也可以在命令行里直接用mvn运行,如下注释说明。
更详细的信息和配置方法,可参考http://mojo.codehaus.org/exec-maven-plugin/usage.html说明。

<!-- commandline: mvn exec:java -Dexec.mainClass="org.phpfirefly.test.Server" -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>org.phpfirefly.test.Server</mainClass>
</configuration>
</plugin>

maven2 repository server install

以下为安装免费版本的nexus maven2服务器和简单的设置过程:


$> wget http://nexus.sonatype.org/downloads/nexus-oss-webapp-1.8.0-bundle.tar.gz
$> tar zxvf nexus-oss-webapp-1.8.0-bundle.tar.gz
$> mv nexus-webapp-1.8.0-bundle /usr/local/nexus
$> cd /usr/local/nexus
$> ls bin/jsw/
$> bin/jsw/linux-x86-32/nexus start
$> tail -f logs/wrapper.log

启动服务后默认URL为:http://localhost:8081/nexus
默认的登录名和密码:admin/admin123
nexus默认是关闭远程索引下载功能的,主要是担心会造成对服务器的巨大负担,需要我们手工开启。
开启的方式: 点击Administration菜单下面的Repositories,将这4个仓库Apache Snapshots,Google code,Codehaus Snapshots,Maven Central的Configuration - Download Remote Indexes修改为true。然后在这三个仓库上分别右键,选择reIndex,这样Nexus就会去下载远程的索引文件。
部署构件至Nexus: Nexus提供了两种方式来部署构件,你可以从UI直接上传,也可以配置Maven部署构件,在上传一个版本时,可以将jar包和source jar包一起上传。

本地maven仓库配置文件,默认位置在用户根目录下的".m2"目录,文件名为settings.xml,如果没有,则创建一份,更新内容如下:

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">

<pluginGroups>
<!-- pluginGroup
| Specifies a further group identifier to use for plugin lookup.
<pluginGroup>com.your.plugins</pluginGroup>
-->
<pluginGroup>org.mortbay.jetty</pluginGroup>
</pluginGroups>

<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>local nexus</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus</id>
<name>local nexus</name>
<url>http://localhost:8081/nexus/content/groups/public/</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>

References: http://juvenshun.javaeye.com/blog/349534
http://wj98127.javaeye.com/blog/306358

Friday, November 05, 2010

get Xpath of html element

在Firefox中有二个非常有用的插件,可以直接得到HTML页面中元素的XPath:

XPath Checker - suggests XPath and can be used to test XPath results.
Firebug - XPath suggestions are just one of the many powerful features of this very useful add-on.

XPath的参考资料:

W3Schools XPath Tutorial
W3C XPath Recommendation
XPath Tutorial - with interactive examples