`
desert3
  • 浏览: 2142481 次
  • 性别: Icon_minigender_1
  • 来自: 合肥
社区版块
存档分类
最新评论

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

模块的构成
由下面的内容可以看到,模块的构成和一般的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命令来创建模块的时候,会自动创建上面的所有文件和文件夹,如果其中的部分文件、文件夹不需要,那么最好删除使得模块看起来更加容易理解。
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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics