• 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"
          }
        ]
      }
  • 相关阅读:
    自注意力中的不同的掩码介绍以及他们是如何工作的?
    sklearn 中的两个半监督标签传播算法 LabelPropagation和LabelSpreading
    Linux 操作指令
    在 KubeSphere 中使用 DevOps 部署 Java 微服务配置监控预警
    Hbase学习
    Linux系统swappiness参数在内存与交换分区之间优化作用
    Linux shell中2>&1的含义解释
    kafka 学习
    Grafana 重置admin密码
    linuxsource: not found ubuntu执行脚本报错
  • 原文地址:https://www.cnblogs.com/silentdoer/p/13552897.html
Copyright © 2020-2023  润新知