play Modules & 使用成熟的Java模块、框架、Spring & 模块和插件的区别

play module repository:这里的模块仓库是给Play 1.x用的( 注意,这里的所有module都是定制的,譬如spring-1.0.2module,1.0.2是模块的版本,而里面包含的sprin的版本是2.5.5)。Play 2.x的模块可以放在Ivy, Maven 或者 Git仓库。

play 1.x的Spring模块:允许在play中使用Spring来管理java bean。其源代码和使用方法在 https://github.com/pepite/Play--framework-Spring-module

安装spring模块:使用命令play install spring-{version}在本地安装
项目中使用spring模块:在dependencies.yml中使用下述命令来引入对spring模块的依赖。
Java代码   收藏代码
  1. require:  
  2.     - play -> spring {version}  

模块和插件的区别:模块是用来给你主应用程序服务的小应用程序。插件是一些java代码,这些java代码和Play内部的插件机制打交道。
The first is word is module and the second is plugin. Module means the little application which serves your main application, where as plugin represents a piece of Java code, which connects to the mechanism of plugins inside Play.
编写自己的模块Play Framework: Introduction to Writing Modules

引用自己编写的模块、外网的模块、play 1.x自带的模块:在编写模块的conf目录下dependencies.yml文件中,通过self: customModules -> firstmodule 1.0来表明模块的版本和名字。依赖编写完成后,执行play命令后会在当前项目目录下生成modules文件夹,里面是需要引用的模块内容。
dependencies.yml
Html代码   收藏代码
  1. require:  
  2.     - play  
  3.     # 默认引用play 1.x仓库中的模块  
  4.     - play -> spring 1.0.1  
  5.     # 依赖自己编写的模块firstmodule,模块的内容从本地仓库中找  
  6.     - customModules -> firstmodule  
  7.     # 引用googlecode仓库中的模块  
  8.     - com.googlecode.lambdaj -> lambdaj 2.3.3  
  9.   
  10. repositories:  
  11.   
  12.     - playCustomModules:  
  13.         # 注意,type是local代表,仓库在本地文件  
  14.         type: local  
  15.         # 这里用绝对路径,或者使用${play.path}代表play的安装路径  
  16.         artifact: "/absolute/path/to/firstmodule/"  
  17.         contains:  
  18.             # 这个名字和上面本地依赖时的名字想对应  
  19.             - customModules -> *  
  20.   
  21.     - googlecode:  
  22.         type:  iBiblio   
  23.         root: "http://lambdaj.googlecode.com/svn/repo/releases/"  
  24.         contains:   
  25.             - com.googlecode.lambdaj -> *   

模块的构成
由下面的内容可以看到, 模块的构成和一般的play应用程序很类似。都有models、views、tags、controllers、conf目录。
其中的区别就是 module中不应该有application.conf文件。而在模块的根目录中多出来2个文件,1,build.xml:ant文件,用来编译模块,并根据编译后的代码生成以模块名字命名的jar包,放置到lib目录; 2,commands.py:python文件,可以在里面增加一些特殊的指定,比如play firstmodule:hello
其他额外需要的jar包也放置在lib目录,在模块被加载的时候,这里的所有jar包会自动放置到classpath中。
src文件夹放置模块的内容,包含模块的逻辑和模块插件的代码,同时包含play.plugins文件,play.plugins文件中包含一行内容1000:play.modules.spring.SpringPlugin,前面的数字代码应用程序加载模块时的顺序,数字越小,越早被加载。后半部分代码模块插件的入口。
当使用Play new-module命令来创建模块的时候,会自动创建上面的所有文件和文件夹,如果 其中的部分文件、文件夹不需要,那么最好删除使得模块看起来更加容易理解。
Html代码   收藏代码
  1. app/controllers/firstmodule  
  2. app/models/firstmodule  
  3. app/views/firstmodule  
  4. app/views/tags/firstmodule  
  5. build.xml  
  6. commands.py  
  7. conf/messages  
  8. conf/routes  
  9. lib  
  10. src/play/modules/firstmodule/MyPlugin.java  
  11. src/play.plugins 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值