备注:

*   ballerina 程序员可以将代码放到一个文件或者一个项目目录

*   一个ballerina program是一个已经编译以及链接的二进制文件

*   package是一个包含ballerina 源码文件的目录

*   repository是一个版本化的已经编译或者源码

*    project自动管理包以及程序的集合

1.   program

程序是运行时可执行的,以balx 为扩展名,程序包必须包含一个main() 函数(一个进程的进入点),或者一个service (网络可访问的api)

参考(包含一个main 以及service  demo.bal):

import ballerina/http;
import ballerina/io; function main (string... args) {
io:println("Hello, World!");
} service<http:Service> hello bind { port: 9090 } {
sayHello (endpoint caller, http:Request req) {
http:Response res = new;
res.setPayload("Hello, World!");
_ = caller->respond(res);
}
} 运行: ballerina run demo.bal 如何只包含service 可以使用
ballerian run -s demo.bal 构建: ballerina build demo.bal

2.  package

包可以实现共享,以及重用
包具有以下特点:
a. 可以有一个可选的版本
b. 但是没有版本的包是不能发布到一个仓库实现代码的共享
c. 包的使用是以 org-name/package-name 格式引用的,org-name在仓库中做为命名空间 包的导入格式:
import [<org-name>]/<package-name> her.package [ [version <string>] [as <identifier>] ];
最后一个包的名称,或者距离最近一个.的字符串为包的标示,可以用来进行包中服务或者共享函数的使用,同时可以
使用as 进行别名命名
比如:
import ballerina/http; http: 做为标示符
import tyler/net.http.exception exception: 做为标示符 参考代码: import ballerina/http; # The 'Service' object comes from the imported package.
service<http:Service> hello bind { port:9090 } { # The 'Request' object comes from the imported package.
sayHello (endpoint caller, http:Reqeust req) {
...
}
} import ballerina/http as network; service<network:Service> hello bind { port:9090 } { # The 'Request' object comes from the imported package.
sayHello (endpoint caller, network:Reqeust req) {
...
}
} 包的版本依赖:
如下,如果没有使用的是latest
import tyler/http version 3.0.1; 导入不同版本的包
import tyler/http version 3.0.1 as identity3;
import tyler/http version 4.5.0 as identity4; function main(string... args) {
identity3:Person x = identity3:getPerson();
identity4:Person y = identity4:getPerson();
}

3. project

project 具有如下特点:

*  一个project 是一个目录自动会进行包以及程序的管理
* 同时包含一个用户管理清单文件 Ballerina.toml
* 一个托管的.ballerina/文件实现元数据以及cache
* project 的repository进行以来的存储 a. 创建project ballerina init -i 按照提示操作即可 b. 创建一个包 每一个根目录子目录都是一个单独的包,子目录名称就是包的名称
.ballerina/, tests/, and resources/ 做为保留目录,不会做为包 一个参考的结构 /
.gitignore
Ballerina-lock.toml # Generated during build, used to rebuild identical binary
Ballerina.toml # Configuration that defines project intent
.ballerina/ # Internal cache management and contains project repository
# Project repository is built or downloaded package dependencies main.bal # Part of the “unnamed” package, compiled into a main.balx
# You can have many files in the "unnamed" package, though unadvisable package1/ # The source in this directory will be named “<org-name>/package1”
Package.md # Optional, contains descriptive metadata for display at Ballerina Central
*.bal # In this dir and recursively in subdirs except tests/ and resources/
[tests/] # Package-specific unit and integration tests
[resources/] # Package-specific resources
*.jar # Optional, if package includes native Java libraries to link + embed packages.can.include.dots.in.dir.name/
Package.md
*.bal
*.jar
[tests/]
[resources/]
*.jar # Optional, if package includes native Java libraries to link + embed [tests/] # Tests executed for every package in the project
[resources/] # Resources included with every package in the project target/ # Compiled binaries and other artifacts end up here
main.balx
package1.balo
packages.can.include.dots.in.dir.name.bal c. 构建一个project ballerina build d. 构建一个包
ballerina build package-name

4. repository

仓库是包的集合,仓库帮助团队或者组织进行管理他们代码的版本以及资源
存在四类仓库:
a. project 仓库,这个是本地的在 ./ballerina 文件夹
b. home 仓库这个目录在开发者的本地
c. system 仓库 一个特殊的仓库,包含在ballerian 的分发包中,主要是ballerian 的一个核心包
d. ballerina 中心仓库,http://central.ballerina.io 仓库的操作: ballerina install
ballerina push --repository=home
ballerina pull <org-name>/<package-name>[:<version>] [--repository=<url>] (remote)
ballerina push <org-name>/<package-name>:<version> [--repository=home|url](remote)
ballerina remove <org-name>/<package>:<version> [--repository=home|<url>]

5. 参考资料

https://ballerina.io/learn/how-to-structure-ballerina-code/
 
 
 
 

ballerina 学习四 如何进行项目结构规划的更多相关文章

  1. ballerina 学习二十六 项目docker 部署&& 运行(二)

    ballerina 从发布,到现在官方文档的更新也是很给力的,同时也有好多改进,越来越好用了 可以参考官方文档 https://ballerina.io/learn/by-guide/restful- ...

  2. spring学习(四) ———— 整合web项目(SSH)

    清楚了spring的IOC 和 AOP,最后一篇就来整合SSH框架把,记录下来,以后应该会用的到. --WH 一.web项目中如何使用spring? 当tomcat启动时,就应该加载spring的配置 ...

  3. ballerina 学习二十五 项目docker 部署&& 运行

    ballerina 官方提供了docker 的runtime,还是比较方便的 基本项目创建 使用cli创建项目 按照提示操作就行 ballerina init -i 项目结构 添加了dockerfil ...

  4. shiro基础学习(四)—shiro与项目整合

    一.认证 1.配置web.xml   2.配置applicationContext.xml      在applicationContext.xml中配置一个bean,ID和上面的过滤器的名称一致. ...

  5. Spring Boot 项目学习 (四) Spring Boot整合Swagger2自动生成API文档

    0 引言 在做服务端开发的时候,难免会涉及到API 接口文档的编写,可以经历过手写API 文档的过程,就会发现,一个自动生成API文档可以提高多少的效率. 以下列举几个手写API 文档的痛点: 文档需 ...

  6. 实验十四:团队项目评审&课程学习总结

    项目 内容 作业所属课程 所属课程 作业要求 作业要求 课程学习目标 (1)掌握软件项目评审会流程:(2)反思总结课程学习内容 任务一:团队项目审核已完成.项目验收过程意见表已上交. 任务二:课程学习 ...

  7. ballerina 学习二十七 项目k8s部署&& 运行

    ballerina k8s 部署和docker 都是同样的简单,编写service 添加注解就可以了 参考项目 https://ballerina.io/learn/by-guide/restful- ...

  8. 十一、Android学习第十天——项目开始(转)

    (转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 十一.Android学习第十天——项目开始 Android知识点的学习告一 ...

  9. VUE2 第六天学习--- vue单文件项目构建

    阅读目录 VUE2 第六天学习--- vue单文件项目构建 回到顶部 VUE2 第六天学习--- vue单文件项目构建 VUE单文件组件在Vue项目中,然后使用 new Vue({el: '#cont ...

随机推荐

  1. 搞懂分布式技术3:初探分布式协调服务zookeeper

    搞懂分布式技术3:初探分布式协调服务zookeeper 1.Zookeepr是什么 Zookeeper是一个典型的分布式数据一致性的解决方案,分布式应用程序可以基于它实现诸如数据发布/订阅,负载均衡, ...

  2. superset dashboard 设置自动刷新

    因为发现了,自己制作了看板dashboard,却不会刷新,很奇怪. 那这样不是太傻了.难道要业务人员一个个去点吗? 一定有刷新的,然后和无头苍蝇在网上找了半天. 实际刷新的位置在这里. 具体设置有很多 ...

  3. Java Web中Kaptcha实现验证码

    首先进行导入相应的jar包: 1.如果是maven项目,在你的pom文件中进行添加如下代码,将自动下载jar包到你的工程中: <dependency>            <gro ...

  4. 转载:【Oracle 集群】RAC知识图文详细教程(二)--Oracle 集群概念及原理

    文章导航 集群概念介绍(一) ORACLE集群概念和原理(二) RAC 工作原理和相关组件(三) 缓存融合技术(四) RAC 特殊问题和实战经验(五) ORACLE 11 G版本2 RAC在LINUX ...

  5. LeetCode OJ:Reverse Bits(旋转bit位)

    Reverse bits of a given 32 bits unsigned integer. For example, given input 43261596 (represented in ...

  6. easyui(1)

    使用Easyui1.引入必要的文件 1).jquery核心库 2).easyui核心库 3).easyui中文提示信息 4).自己开发的js文件 5).easyui核心UI文件css 6).easyu ...

  7. Javascript-- jQuery动画篇(2)

    动画效果 前面的 hide/show,slide in/out 其实也具有动画效果,本篇介绍使用 animate()实现自定义动画效果. 基本语法如下: $(selector).animate({pa ...

  8. vue.js 源代码学习笔记 ----- $watcher

    /* @flow */ import { queueWatcher } from './scheduler' import Dep, { pushTarget, popTarget } from '. ...

  9. Android6.0之后的权限机制对App开发的影响

    随着Android系统的更新换代,每次重大更新的方面也逐步扩展,从4.*主要是增强功能,到5.*主要是美化界面,到6.*主要提高系统安全性,再到7.*和8.*主要支撑各种大屏设备,因此开发者需要对每个 ...

  10. 在线机器学习FTRL(Follow-the-regularized-Leader)算法介绍

    看到好文章,坚决转载!哈哈,学术目的~~ 最近几个同事在做推荐平台的项目,都问到怎么实现FTRL算法,要求协助帮忙实现FTRL的算法模块.今天也是有空,赶紧来做个整理.明天还要去上海参加天善智能组织的 ...