dart 替代java_dart里实现类似Java里的--classpath的功能

dart里目前不清楚可不可以像Java一样指定一个classpath option(看了下dart --help好像--packages很像,但是可能是我path格式有问题,反正没成功),但是可以在dart项目根目录里添加 .dart_tool 目录,然后在里面添加 package_config.json 文件,

然后文件里写这样的配置即可实现将其他地方的库作为此项目的依赖库:

{

"configVersion": 2,

"packages": [

{

"name": "dart_console",

"rootUri": "file:///home/silentdoer/.pub-cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub/dart_console-0.6.2",

"packageUri": "lib/",

"languageVersion": "2.7"

},

{

"name": "ffi",

"rootUri": "file:///home/silentdoer/.pub-cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub/ffi-0.1.3",

"packageUri": "lib/",

"languageVersion": "2.6"

},

{

"name": "win32",

"rootUri": "file:///home/silentdoer/.pub-cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub/win32-1.6.10",

"packageUri": "lib/",

"languageVersion": "2.7"

}

]

}

即,这里用到了三个依赖库(注意,包括递归依赖);

不过它还可以进一步精简:

{"configVersion": 2,"packages": [

{"name": "dart_console","rootUri": "file:///home/silentdoer/.pub-cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub/dart_console-0.6.2","packageUri": "lib/"},

{"name": "ffi","rootUri": "file:///home/silentdoer/.pub-cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub/ffi-0.1.3","packageUri": "lib/"},

{"name": "win32","rootUri": "file:///home/silentdoer/.pub-cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub/win32-1.6.10","packageUri": "lib/"}

]

}

还能再简化:

{"configVersion": 2,"packages": [

{"name": "dart_console","rootUri": "/home/silentdoer/.pub-cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub/dart_console-0.6.2","packageUri": "lib/"},

{"name": "ffi","rootUri": "/home/silentdoer/.pub-cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub/ffi-0.1.3","packageUri": "lib/"},

{"name": "win32","rootUri": "/home/silentdoer/.pub-cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub/win32-1.6.10","packageUri": "lib/"}

]

}

而且,rootUri可以用相对路径,注意,它相对的是package_config.json文件的位置

{"configVersion": 2,"packages": [

{"name": "dart_console","rootUri": "../../packages/dart_console-0.6.2","packageUri": "lib/"},

{"name": "ffi","rootUri": "/home/silentdoer/.pub-cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub/ffi-0.1.3","packageUri": "lib/"},

{"name": "win32","rootUri": "/home/silentdoer/.pub-cache/hosted/mirrors.tuna.tsinghua.edu.cn%2547dart-pub/win32-1.6.10","packageUri": "lib/"}

]

}

而,这里比如dart_console的目录结构(其实就是一个git项目)是这样的:

analysis_options.yaml  example  LICENSE       README.md

CHANGELOG.md           lib      pubspec.yaml  test

它们在dart_console-0.6.2目录里;(经过测试,运行程序其实只需要依赖项目的lib目录即可,即上面的目录除了lib目录都可以删掉)

这里还可以简写成这样:

{"configVersion": 2,"packages": [

{"name": "dart_console","rootUri": "../../packages/dart_console-0.6.2/lib/"},

{"name": "ffi","rootUri": "../../packages/ffi-0.1.3/lib"},

{"name": "win32","rootUri": "../../packages/win32-1.6.10/lib"}

]

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值