执行内存jar [英] Executing an in memory jar
本文介绍了执行内存jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个java进程以byte []的形式从可信进程接收可运行的jar文件,有没有办法调用它而不必将jar文件写入磁盘然后调用它(启动一个运行jar的新进程?
Suppose I have a java process that is receiving a runnable jar file from a trusted process in the form of a byte [], is there a way to invoke it without having to write the jar file to disk and then invoke it(start a new process that is running the jar)?
推荐答案
这是一种可以实现它的方法:
Here is one way you can accomplish it:
- 从
byte []
ByteArrayInputStream >收到。 -
现在使用
JarInputStream
,用于创建jar文件的内存中表示形式。
- Create a
ByteArrayInputStream
from thebyte []
received. Now use
JarInputStream
to create in-memory representation of the jar file.
ByteArrayInputStream bis = new ByteArrayInputStream(byteArray);
JarInputStream jis = new JarInputStream(bis);
这样你就可以在内存中加载jar了。
This way you have the jar loaded in the memory.
这篇关于执行内存jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文