本站首页    管理页面    写新日志    退出


«September 2025»
123456
78910111213
14151617181920
21222324252627
282930


公告
 本博客在此声明所有文章均为转摘,只做资料收集使用。

我的分类(专题)

日志更新

最新评论

留言板

链接

Blog信息
blog名称:
日志总数:1304
评论数量:2242
留言数量:5
访问次数:7605140
建立时间:2006年5月29日




[Java Open Source]Integrate Compass, Appfuse, DisplayTag Tutorial Part 1
软件技术

lhwork 发表于 2007/1/23 9:00:18

The goal of this tutorial is to make a happy Compass   Add required libs and config spring to make Appfuse and Compass work together.   The source could be download here.   I remove lib, extra, docs folder to reduce size.   Step 1. Prepare sources.   1. appfuse 1.9.3, download here  https://appfuse.dev.java.net/   2. Compass 1.1M1  http://www.opensymphony.com/compass/  Step 2. Create Appilication and Add jars to lib   1. In appfuse, run "ant new" to create a new web application   Here we use "myapp" as new web application name    You could check the image here  2. Switch java compiler compliance to 5.0   Compass offers annotation to generate cpm file.   To use this feature, we have to change to jdk 5.0 compliance to enable annotation   If you use Eclipe as IDE, in Window -> Preference -> Java -> Compiler     Switch Compiler compiliance level to JDK 5.0   You could check the image here   3. Create folder named "compass-1.1" under myapp/lib path     Add           compass.jar      compass-annotations.jar      lucene-analyzers.jar      lucene-core.jar      lucene-highlighter.jar      lucene-snowball.jar        These jars could be found in compass dist folder.    Note. Here is little difference with Chris Barham's steps  1. Appfuse already has commons-logging.jar, I did not add it again.  2. For annotation to generate resource mapping, I add compass-annotations.jar   3. compass-1.1M1-with-dependencies uses spring 2.0 but Appfuse comes with spring 1.2.8 instead of 2.0    I pick up 1.2.8 to try and work well, so I did not use 2.0    4. edit lib.properties and add below   #  # Compass search http://www.opensymphony.com/compass/  #  compass.version=1.1  compass.dir=${lib.dir}/compass-${compass.version}    You could check the image here  5. edit properties.xml   find "service.compile.classpath", "web.compile.classpath" and add bellow    <fileset dir="${compass.dir}" includes="*.jar" />  6. edit "build.xml"   find ant task "package-web" and add bellow      <lib dir="${compass.dir}" includes="*.jar"/>   7. create file named "myapp.cpm.xml", add it to src\service\org\myapp\service     ------ start here ------  <?xml version="1.0"?><!DOCTYPE compass-core-mapping PUBLIC    "-//Compass/Compass Core Mapping DTD 1.0//EN"    "http://www.opensymphony.com/compass/dtd/compass-core-mapping.dtd"> <compass-core-mapping package="org.myapp.model">  <!-- ============================================= --> <!--  USER           --> <!-- ============================================= --> <class name="User" alias="user" root="true">  <id name="id" />  <constant>   <meta-data>type</meta-data>   <meta-data-value>user</meta-data-value>  </constant>  <property name="lastName">   <meta-data boost="2">lastName</meta-data>  </property>  <property name="firstName">   <meta-data>firstName</meta-data>  </property>  <property name="enabled">   <meta-data>enabled</meta-data>  </property>  <property name="phoneNumber">   <meta-data>phoneNumber</meta-data>  </property>  <property name="email">   <meta-data>email</meta-data>  </property>  <property name="address">   <meta-data>address</meta-data>  </property>  <property name="email">   <meta-data>email</meta-data>  </property>  <property name="accountExpired">   <meta-data>accountExpired</meta-data>  </property>  <property name="accountLocked">   <meta-data>accountLocked</meta-data>  </property>  <property name="username">   <meta-data>username</meta-data>  </property>  <property name="website">   <meta-data>website</meta-data>  </property>   <component name="roles" ref-alias="role" />  <component name="address" ref-alias="address" /> </class> <!-- ============================================= --> <!--  ROLE            --> <!-- ============================================= --> <class name="Role" alias="role" root="false">  <id name="id" />  <constant>   <meta-data>type</meta-data>   <meta-data-value>role</meta-data-value>  </constant>  <property name="description">   <meta-data>description</meta-data>  </property>  <property name="name">   <meta-data>name</meta-data>  </property> </class> <!-- ============================================= --> <!--  ADDRESS            --> <!-- ============================================= --> <class name="Address" alias="address" root="false">  <constant>   <meta-data>type</meta-data>   <meta-data-value>address</meta-data-value>  </constant>  <property name="address">   <meta-data>address</meta-data>  </property>  <property name="city">   <meta-data>address</meta-data>  </property>  <property name="country">   <meta-data>address</meta-data>  </property>  <property name="postalCode">   <meta-data>address</meta-data>  </property>  <property name="province">   <meta-data>address</meta-data>  </property> </class> </compass-core-mapping>     ------ end here------          8. Edit applicationContext-service.xml and add below     <!-- COMPASS START -->     <bean id="compass" class="org.compass.spring.LocalCompassBean">    <property name="resourceLocations">   <list>    <value>classpath:org/myapp/service/myapp.cpm.xml</value>   </list>  </property>  <property name="compassSettings">   <props>    <prop key="compass.engine.connection">file:///compass/myapp</prop>    <prop key="compass.transaction.factory">org.compass.spring.transaction.SpringSyncTransactionFactory</prop>   </props>  </property>  <property name="transactionManager" ref="transactionManager" /> </bean> <bean id="hibernateGpsDevice" class="org.compass.spring.device.hibernate.SpringHibernate3GpsDevice">  <property name="name">   <value>hibernateDevice</value>  </property>  <property name="sessionFactory" ref="sessionFactory" />  </bean> <bean id="compassGps" class="org.compass.gps.impl.SingleCompassGps" init-method="start" destroy-method="stop">  <property name="compass">   <ref bean="compass" />  </property>  <property name="gpsDevices">   <list>    <bean class="org.compass.spring.device.SpringSyncTransactionGpsDeviceWrapper">     <property name="gpsDevice" ref="hibernateGpsDevice" />    </bean>   </list>  </property> </bean>  <!-- COMPASS END -->    9. Run "ant test-web" and check if index files created   In  applicationContext-service.xml I use <prop key="compass.engine.connection">file:///compass/myapp</prop>   In my case the files are located in C:\compass\myapp\index\user     You should have _0.cfs           _0.del           _1.cfs           _2.cfs           _3.cfs           deletable           segments           10. See what we have done   To check index results, I use luke as lucene monitor     You can get it from http://www.getopt.org/luke/   In this case, we index User, Role and Address  Congraguration !! You already have a running search engine work happy with Appfuse ^^   Summary   In this tutorial, we setup basic env to have a running compass in Appfuse.    In next part, we will create actions and ant tasks that help us create and delete index.


阅读全文(3625) | 回复(0) | 编辑 | 精华
 



发表评论:
昵称:
密码:
主页:
标题:
验证码:  (不区分大小写,请仔细填写,输错需重写评论内容!)



站点首页 | 联系我们 | 博客注册 | 博客登陆

Sponsored By W3CHINA
W3CHINA Blog 0.8 Processed in 0.047 second(s), page refreshed 144766942 times.
《全国人大常委会关于维护互联网安全的决定》  《计算机信息网络国际联网安全保护管理办法》
苏ICP备05006046号