• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

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

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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人参与评论

请发表评论

全部评论

专题导读
上一篇:
dart系列之:集合使用最佳实践发布时间:2022-07-13
下一篇:
5.Controlflowstatements-流程控制(Dart中文文档)发布时间:2022-07-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap