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

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

[url=http://www.playframework.org/modules/spring]play 1.x的Spring模块[/url]:允许在play中使用Spring来管理java bean。其源代码和使用方法在[url]https://github.com/pepite/Play--framework-Spring-module[/url]

[b]安装spring模块[/b]:使用命令play install spring-{version}在本地安装
[b]项目中使用spring模块[/b]:在dependencies.yml中使用下述命令来引入对spring模块的依赖。

require:
- play -> spring {version}

[b]模块和插件的区别[/b]:模块是用来给你主应用程序服务的小应用程序。插件是一些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.
[b]编写自己的模块[/b]:[url=http://www.packtpub.com/article/play-framework-introduction-writing-modules]Play Framework: Introduction to Writing Modules[/url]

[b]引用自己编写的模块、外网的模块、play 1.x自带的模块[/b]:在编写模块的conf目录下dependencies.yml文件中,通过self: customModules -> firstmodule 1.0来表明模块的版本和名字。依赖编写完成后,执行play命令后会在当前项目目录下生成modules文件夹,里面是需要引用的模块内容。
dependencies.yml

require:
- play
# 默认引用play 1.x仓库中的模块
- play -> spring 1.0.1
# 依赖自己编写的模块firstmodule,模块的内容从本地仓库中找
- customModules -> firstmodule
# 引用googlecode仓库中的模块
- com.googlecode.lambdaj -> lambdaj 2.3.3

repositories:

- playCustomModules:
# 注意,type是local代表,仓库在本地文件
type: local
# 这里用绝对路径,或者使用${play.path}代表play的安装路径
artifact: "/absolute/path/to/firstmodule/"
contains:
# 这个名字和上面本地依赖时的名字想对应
- customModules -> *

- googlecode:
type: iBiblio
root: "http://lambdaj.googlecode.com/svn/repo/releases/"
contains:
- com.googlecode.lambdaj -> *

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

app/controllers/firstmodule
app/models/firstmodule
app/views/firstmodule
app/views/tags/firstmodule
build.xml
commands.py
conf/messages
conf/routes
lib
src/play/modules/firstmodule/MyPlugin.java
src/play.plugins
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值