繁体   English   中英

使用 NodeJS 提取.jar 文件

[英]Extract .jar file with NodeJS

我需要使用 NodeJS 提取 JAR 文件,但我不知道如何,我也不确定 StackOverFlow 是否适合这个地方,如果不是,很抱歉。

so jar files are just java archive files that can be unzipped with any commonly available operating system tool like unzip or jar , so a simple command like jar xvf /path/to/file.jar or unzip /path/to/file.jar should提取任何.jar 文件。 但是,由于您想使用 nodeJS 来执行此操作,因此可以使用 node js 代码模块中名为child_processexec function 。

您可以创建一个简单的 function ,它包含 jar 文件的路径,例如

const exec = require('child_process').exec;

extractJar(path) => {
  const command = `jar xvf ${path}`;
  exec(command, (err, stdout) => {
    if(err) console.log(err); return;
    console.log('success!');
  })
}

或者,您尝试使用unzipper之类的库,这些库不依赖于您的操作系统工具,因为 exec 命令仅在 shell 上执行该过程,但这些库使用您的节点 js IO 操作进行提取。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM