首页 \ 问答 \ Maven对原始Spring Boot JAR的依赖[重复](Maven dependency on original Spring Boot JAR [duplicate])

Maven对原始Spring Boot JAR的依赖[重复](Maven dependency on original Spring Boot JAR [duplicate])

这个问题在这里已有答案:

我正在使用Spring Boot和spring boot maven插件创建一个JAR

插件创建的JAR将类放在JAR的子目录中,这意味着我不能将JAR用作maven中的依赖项。

有没有办法在原始JAR上声明maven中的依赖性。 我看到target目录中有一个*.jar.original文件,所以也许我可以通过声明类型test-jar的依赖关系来创建对测试类的依赖关系。

只是为了澄清:我正在进行此测试/更容易调试,而不是用于生产。


This question already has an answer here:

I'm using Spring Boot with the spring boot maven plugin which creates a JAR with

The JAR created by the plugin puts the classes in subdirectory in the JAR which means that I can't use the JAR as a dependency in maven.

Is there a way to declare a depenency in maven on the original JAR. I see that there is a *.jar.original file in the target directory so maybe I can create a dependency on that in the way it's possible to create a dependency on the test classes by declaring a dependency of the kind test-jar.

Just for clarification: I'm doing this testing/easier debugging, not for production.


原文:
更新时间:2022-01-22 06:01

最满意答案

只需使用try: ... except: ...块即可。 如果有些奇怪的事情导致线程失败,很可能在你的代码的某个地方抛出一个错误(而不是在线程子系统本身)。 这样你可以捕捉它,记录它,然后重新启动线程。 无论您是想要关闭线程并启动一个新线程,还是只将try/except块放在while循环中,以便同一线程继续运行,这都是您的呼叫。

另一个解决方案,如果你怀疑可能发生的事情,你无法通过Python的错误处理机制检测到,那就是启动一个监视器线程,定期检查其他线程是否正常运行。


Just use a try: ... except: ... block in the run method. If something weird happens that causes the thread to fail, it's highly likely that an error will be thrown somewhere in your code (as opposed to in the threading subsystem itself); this way you can catch it, log it, and restart the thread. It's your call whether you want to actually shut down the thread and start a new one, or just enclose the try/except block in a while loop so the same thread keeps running.

Another solution, if you suspect that something really weird might happen which you can't detect through Python's error handling mechanism, would be to start a monitor thread that periodically checks to see that the other threads are running properly.

相关问答

更多
  • 首先,您实际上需要保存所有这些thread对象以在它们上调用join() 。 正如所写,你只保存最后一个,然后只有没有例外。 执行多线程编程的简单方法是为每个线程提供运行所需的所有数据,然后让它不写入该工作集以外的任何内容。 如果所有线程遵循该指导原则,他们的写作不会互相干扰。 然后,一旦一个线程完成,让主线程只将结果聚合成一个全局数组。 这被称为“分叉/连接并行”。 如果您创建了Thread对象的子类,则可以给它留出空间来存储该返回值,而不会干扰其他线程。 然后你可以做这样的事情: class MyThr ...
  • 不幸的是,多线程共享的套接字不是线程安全的。思考缓冲区,两个线程无锁地操作。 正常的实现方式是使用两个套接字,就像ftp.cmd套接字和msg套接字一样。 如果你想通过一个套接字来实现这一点,你可以把不同类型的消息放到不同的队列中,并且第三个线程使用队列并通过唯一套接字发送它们。 通过这种方式,你可以控制心跳信号msg priory到数据msg。 Unfortunately,The socket shared by multi-thread is not thread safe.Think about bu ...
  • 使用threading.Event而不是布尔值。 它的构建由多线程监控。 在这个例子中, task_a和task_a_monitor运行不同的费率,但等待相同的事件。 主线程通过set和clear方法来控制它们。 我包含一个布尔值,用于告诉线程他们的工作已经完成并且需要退出时间 - 但是只有在事件设置时才会有影响。 import threading import time # use to start/pause/exit task task_event = threading.Event() task_ ...
  • 对于你的特定任务,我会推荐一个多处理工作者池 。 您只需定义一个池,然后告诉它要使用多少个进程(默认情况下每个处理器核心一个)以及要在每个工作单元上运行的函数。 然后,您准备好列表中的每个工作单元 (在您的情况下,这将是一个URL列表)并将其提供给工作人员池。 您的输出将是您原始数组中每项工作的工作函数返回值的列表。 所有酷酷的多处理善良都会在后台发生。 当然,还有其他与工作人员合作的方式,但这是我最喜欢的方式。 快乐的多处理! For your specific task I would recommen ...
  • Python使用“真实”线程,即底层平台的线程。 在Linux上,它将使用pthread库(如果你感兴趣, 这里是实现 )。 Python的线程有什么特别之处:GIL:如果一个线程拥有这个全局锁,它就只能修改Python数据结构。 因此,许多Python操作无法使用多个处理器内核。 具有阻塞套接字的线程不会保留GIL,所以它不会影响其他线程。 GIL经常被误解,让人们认为Python中的线程几乎是无用的。 GIL唯一防止的是在多个处理器内核上同时执行“纯”Python代码。 如果您使用线程来创建GUI响应或 ...
  • multiprocessing模块和subprocess进程模块都产生了threading.Thead内部的threading.Thead对象可以帮助处理它们产生的进程的I / O。 具体来说,一旦实例化multiprocessing.Pool ,就会生成三个线程 : class Pool(object): ''' Class which supports an async version of the `apply()` builtin ''' Process = Pro ...
  • 您可以使用threading.enumerate()访问所有当前线程对象,例如 for thread in threading.enumerate(): print(thread.name) You can access all current thread objects using threading.enumerate(), e.g. for thread in threading.enumerate(): print(thread.name)
  • 只需使用try: ... except: ...块即可。 如果有些奇怪的事情导致线程失败,很可能在你的代码的某个地方抛出一个错误(而不是在线程子系统本身)。 这样你可以捕捉它,记录它,然后重新启动线程。 无论您是想要关闭线程并启动一个新线程,还是只将try/except块放在while循环中,以便同一线程继续运行,这都是您的呼叫。 另一个解决方案,如果你怀疑可能发生的事情,你无法通过Python的错误处理机制检测到,那就是启动一个监视器线程,定期检查其他线程是否正常运行。 Just use a try: . ...
  • 你考虑过GIL(Global Interpreter lock)吗? https://wiki.python.org/moin/GlobalInterpreterLock Python有一个GIL,它不允许从一个进程运行多个线程。 运行代码时,它将作为python进程运行。 您正在尝试从python中不允许的同一进程启动线程。 如果要并行执行某些操作,多处理包是一个不错的选择。 https://pymotw.com/2/multiprocessing/basics.html Have you conside ...
  • Pypy不会解决每次运行单线程的Python问题,因为它也使用了GIL - http://doc.pypy.org/en/latest/faq.html#does-pypy-have-a -GIL,为什么 除此之外,Kivy是一个嵌入Python本身的复杂项目 - 尽管我不太了解它,但我怀疑是否有可能将其中使用的Python切换为Pypy。 根据您正在做的事情,您可能希望使用multiprocessing模块而不是threading - 它是一个替代品,可以对Python函数进行透明的进程间调用,因此可以利 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。