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模块的依赖。

快速生产Javabean插件 java插件式 开发模块_spring


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

1. require:  
2.     - play  
3.     # 默认引用play 1.x仓库中的模块  
4. >
5.     # 依赖自己编写的模块firstmodule,模块的内容从本地仓库中找  
6. >
7.     # 引用googlecode仓库中的模块  
8. >
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. >
20.   
21.     - googlecode:  
22.         type:  iBiblio   
23.         root: "http://lambdaj.googlecode.com/svn/repo/releases/"  
24.         contains:   
25. >



模块的构成


由下面的内容可以看到,

模块的构成和一般的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命令来创建模块的时候,会自动创建上面的所有文件和文件夹,如果

其中的部分文件、文件夹不需要,那么最好删除使得模块看起来更加容易理解。

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