首页 \ 问答 \ 在使用命令行工具构建时,如何添加.jar文件依赖项?(How can I add a .jar file dependencies when building it with the command line tool?)

在使用命令行工具构建时,如何添加.jar文件依赖项?(How can I add a .jar file dependencies when building it with the command line tool?)

非常直截了当的问题。 可以在不使用Ants或Maven的情况下完成吗? (顺便说一下,我的意思是命令行工具)

请注意,我不想创建一个uberjar,我只是希望已归档的单元“知道”它的外部依赖关系。


Pretty straightforward question. Can it be done without the use of Ants or Maven? (And by that, I mean the command line tool specifically)

Please notice that I don't want to create an uberjar, I just want the archived unit to "know" where its external dependencies are.


原文:https://stackoverflow.com/questions/6768188
更新时间:2021-12-28 09:12

最满意答案

让我们一个一个地分解它。

Box<T>是一个指向堆分配T的指针。 我们在这里使用它,因为trait对象只能存在于指针后面。

特质对象

Box<Fn() + Send + 'static>Fn() + Send + 'static是一个特征对象类型。 将来,它将被写入Box<dyn (Fn() + Send + 'static)>以避免混淆。

内部dyn是对原始类型的限制。 只有当T: Fn() + Send + 'static时, Box<T>才能被强制转换为Box<Fn() + Send + 'static> 。 因此,尽管我们不知道原始类型,但我们可以假设它是Fn()Send具有'static生命周期”

Fn()

这是一个特性,就像CloneDefault 。 但是,它使用特殊的语法糖

  • Fn(A1, ..., An)Fn<(A1, ..., An), Output=()>的语法糖。
  • Fn(A1, ..., An) -> RFn<(A1, ..., An), Output=R>的语法糖。
  • 此语法糖也适用于以下特征: FnFnMutFnOnceFnBox

那么Fn是什么意思? T: Fn(A1, ..., An) -> R表示x: T是可调用对象,其参数为A1, ..., An ,返回类型为R 例子包括函数指针和闭包。

发送

Send意味着可以通过线程发送此类型的值。 由于这是一个自动特征 ,因此可以将其指定为 dyn类型的第二个边界 (特征对象类型)。

'static界限

事实上, dyn类型(特征对象类型)必须只有一个生命周期界限 。 它被省略时推断。 推理规则在RFC 0192RFC 1156中描述。 基本如下:

  1. 如果明确给出,请使用该生命周期。
  2. 否则,从内在特质推断。 例如, Box<Any>Box<Any + 'static>因为Any: 'static
  3. 如果性状不具有适当的生命周期,则从外部类型推断。 例如, &'a Fn()&'a (Fn() + 'a)
  4. 如果甚至失败了,它会回落到'static (对于函数签名)或匿名生命周期(对于函数体)。

结论

f: Box<Fn() + Send + 'static>是一个拥有指向可调用值的指针(原始类型未知并动态更改),例如闭包(没有参数或没有返回值),可以跨线程发送和程序本身一样长寿。


Let's decompose it one-by-one.

Box

Box<T> is a pointer to heap-allocated T. We use it here because trait objects can only exist behind pointers.

Trait objects

In Box<Fn() + Send + 'static>, Fn() + Send + 'static is a trait object type. In future, it will be written Box<dyn (Fn() + Send + 'static)> to avoid confusion.

Inside dyn are restrictions to the original type. Box<T> can be coerced into Box<Fn() + Send + 'static> only when T: Fn() + Send + 'static. Therefore, although we don't know the original type, we can assume it was Fn() and Send and had 'static lifetime.

Fn()

This is a trait, just like Clone or Default. However, it uses a special syntax sugar.

  • Fn(A1, ..., An) is a syntax sugar for Fn<(A1, ..., An), Output=()>.
  • Fn(A1, ..., An) -> R is a syntax sugar for Fn<(A1, ..., An), Output=R>.
  • This syntax sugar also applies to the following traits: Fn, FnMut, FnOnce, and FnBox.

So what does Fn mean? T: Fn(A1, ..., An) -> R means x: T is a callable object with arguments A1, ..., An and return type R. Examples include function pointers and closures.

Send

Send means that values of this type can be sent across threads. Since this is an auto trait, it can be specified as the second bounds of dyn types (trait object types).

'static bound

In fact, dyn types (trait object types) must have exactly one lifetime bound. It's inferred when omitted. The inference rule is described in RFC 0192 and RFC 1156. It's basically as follows:

  1. If explicitly given, use that lifetime.
  2. Otherwise, it is inferred from the inner trait. For example, Box<Any> is Box<Any + 'static> because Any: 'static.
  3. If the trait doesn't have an appropriate lifetime, it is inferred from the outer type. For example, &'a Fn() is &'a (Fn() + 'a).
  4. If that even failed, it falls back to 'static (for a function signature) or an anonymous lifetime (for a function body).

Conclusion

f: Box<Fn() + Send + 'static> is an owned pointer to a callable value (with the original type unknown and dynamically change) such as closures (with no argument or no return value), which can be sent across threads and lives as long as the program itself.

相关问答

更多
  • &dox的类型不是&Fn(u8) -> u8 (或甚至&fn(u8) -> u8 ),它仅仅是 &Fn(u8) -> u8 。 因此,你实际上正在接受临时地址。 暂时性不会被提升为'static生命期,即使它们原则上可能是'static 。 例如,此代码不起作用: fn main() { let a: &'static i32 = &5; } 有一些解决方法。 通常人们可以明确地创建一个static变量并引用它: fn main() { static FIVE: i32 = 5; ...
  • Fn()的问题是你可以多次调用它。 如果您移出捕获的值,则在下次调用时该值将不再可用。 你需要一个FnOnce()来确保调用闭包也会移出它,所以它不会再被调用。 没有办法让Arc> 。 这将再次要求您静态地保证在您调用该函数后,其他人都不能再次调用它。 你不能这样做,因为别人可能会有另一个Arc指向你的FnOnce 。 你可以做的是将其装箱并发送为Box 。 ...
  • 请注意,应严格检查所实现的特征方法的合规性: send_message(&mut self, user_id: UserId, text: &str)不符合send_message(&self, user_id: UserId, text: &str)因为前者对self的可变引用,编译器最终会抱怨。 因此,这里需要内部可变性,以便状态更改可能发生在不可变引用后面。 在这种情况下,由于您正在处理其他线程安全组件,因此您可以考虑使用线程安全的AtomicBool 。 use std::sync::atomic: ...
  • 问题实际上在这里: pub fn sequential_image( ..., interpolate: &Box Complex64>, ...) -> ... interpolate不期望a &Box Complex64 + Send + Sync> ,而Rust在处理所有这些复杂性的差异方面非常糟糕。 一种解决方案是在所谓的演员阵容中进行: sequential_image(width, height, & ...
  • 陷入僵局,我不明白为什么 你有4个线程,然后调用一次map_parallel ,它map_parallel一个线程,它在退出之前调用map_parallel本身,这会map_parallel一个线程,等等。 在任何线程完成之前,您已经耗尽了线程。 在这个例子中切换到5个线程“修复”了死锁。 显然,根据树的深度来切换线程的数量并不理想。 我建议将你的代码分解成不同的问题。 由于您已经在平行处理事务,因此每个节点都需要彼此独立。 这意味着你可以实现一个迭代器: impl BinaryTree { fn ...
  • 值得注意的是,这是特征对象和通用结构/枚举的一般属性,并且完全不特定于未装箱的闭包, FnOnce , Option或|:| (尤其不是这样,因为它只是创建实现某种特质的价值的好方法)。 另外,最近的RFC#401是相关的。 1)上面的代码应该工作吗? 或者Option <> / Some()意味着一些复杂的东西,我在这方面还没有理解? Box>是一个特征对象,因此与F: FnOnce<...>的非动态Box表示或类型不同。 从理论上讲,我们可以通过某些类型的枚举和结构支持更高级 ...
  • 让我评论一下这个表达式的类型: for s in somethings.list.iter() { K::abc(&s); } (我已经重命名了迭代器变量,以避免混淆)。 something是类型的: Something 。 something.list的类型为: Vec> 。 somethings.list.iter()的类型为std::slice::Iter<...> (不重要)。 s的类型为&Box ...
  • 让我们一个一个地分解它。 框 Box是一个指向堆分配T的指针。 我们在这里使用它,因为trait对象只能存在于指针后面。 特质对象 在Box , Fn() + Send + 'static是一个特征对象类型。 将来,它将被写入Box以避免混淆。 内部dyn是对原始类型的限制。 只有当T: Fn() + Send + 'static时, Box才能被强制转换为Box
  • 我不确定,但我怀疑这不会发生,因为需要进行两次转换,并且需要进行太多的转换。 再次检查错误消息: From> 请注意,错误提到了一个闭包。 在Rust中,每个闭合都是一种独特的,不可摧毁的类型(有时称为Voldemort类型 )。 闭包不是 Fn ,但确实实现了 Fn 。 要使From转换工作,起始类型必须是Box 。 我们可以看到对Box的显式转换允许它编译: call((Box::new(|| pr ...
  • 你不能,而且你不需要。 就键盘电路而言, Fn键仅作为键存在。 当密钥代码被发送到操作系统时,它看起来就像常规键盘上的常规键一样。 操作系统甚至不知道存在Fn键,这是由笔记本电脑中的特殊键盘电路处理的。 要在笔记本电脑上按下功能键,只需像普通键盘一样发送功能键的常规键码。 如果存在使用Fn密钥的任何其他密钥组合,则它们或者具有它们自己的密钥代码,或者它们根本不可能发送,因为它们由笔记本电脑处理,而不是由操作系统处理。 You can't, and you don't need to. The Fn key ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)